package com.mall.coupon.service.impl;

import com.mall.coupon.mapper.HomeSubjectSpuMapper;
import com.mall.coupon.service.HomeSubjectSpuService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.mall.coupon.service.HomeSubjectSpuService;
import com.mall.coupon.domain.dto.HomeSubjectSpuDto;
import com.mall.coupon.domain.entity.HomeSubjectSpu;
import com.mall.coupon.domain.vo.HomeSubjectSpuVo;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.common.domain.vo.result.Result;
import com.mall.common.domain.vo.result.ResultCodeEnum;

import java.util.List;

/**
 * <p>
 * 专题商品 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2025-07-06 11:15:40
 */
@Service
@Transactional
public class HomeSubjectSpuServiceImpl extends ServiceImpl<HomeSubjectSpuMapper, HomeSubjectSpu> implements HomeSubjectSpuService {

    /**
     * * 专题商品 服务实现类
     *
     * @param pageParams 专题商品分页查询page对象
     * @param dto        专题商品分页查询对象
     * @return 查询分页专题商品返回对象
     */
    @Override
    public PageResult<HomeSubjectSpuVo> getHomeSubjectSpuPage(Page<HomeSubjectSpu> pageParams, HomeSubjectSpuDto dto) {
        IPage<HomeSubjectSpuVo> page = baseMapper.selectListByPage(pageParams, dto);

        return PageResult.<HomeSubjectSpuVo>builder()
                .list(page.getRecords())
                .pageNo(page.getCurrent())
                .pageSize(page.getSize())
                .total(page.getTotal())
                .build();
    }

    /**
     * 添加专题商品
     *
     * @param dto 专题商品添加
     */
    @Override
    public void addHomeSubjectSpu(HomeSubjectSpuDto dto) {
        HomeSubjectSpu homeSubjectSpu =new HomeSubjectSpu();
        BeanUtils.copyProperties(dto, homeSubjectSpu);
        save(homeSubjectSpu);
    }

    /**
     * 更新专题商品
     *
     * @param dto 专题商品更新
     */
    @Override
    public void updateHomeSubjectSpu(HomeSubjectSpuDto dto) {
        HomeSubjectSpu homeSubjectSpu =new HomeSubjectSpu();
        BeanUtils.copyProperties(dto, homeSubjectSpu);
        updateById(homeSubjectSpu);
    }

    /**
     * 删除|批量删除专题商品
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteHomeSubjectSpu(List<Long> ids) {
        removeByIds(ids);
    }
}