package com.mall.coupon.service.impl;

import com.mall.coupon.mapper.SkuFullReductionMapper;
import com.mall.coupon.service.SkuFullReductionService;
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.SkuFullReductionService;
import com.mall.coupon.domain.dto.SkuFullReductionDto;
import com.mall.coupon.domain.entity.SkuFullReduction;
import com.mall.coupon.domain.vo.SkuFullReductionVo;
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 SkuFullReductionServiceImpl extends ServiceImpl<SkuFullReductionMapper, SkuFullReduction> implements SkuFullReductionService {

    /**
     * * 商品满减信息 服务实现类
     *
     * @param pageParams 商品满减信息分页查询page对象
     * @param dto        商品满减信息分页查询对象
     * @return 查询分页商品满减信息返回对象
     */
    @Override
    public PageResult<SkuFullReductionVo> getSkuFullReductionPage(Page<SkuFullReduction> pageParams, SkuFullReductionDto dto) {
        IPage<SkuFullReductionVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加商品满减信息
     *
     * @param dto 商品满减信息添加
     */
    @Override
    public void addSkuFullReduction(SkuFullReductionDto dto) {
        SkuFullReduction skuFullReduction =new SkuFullReduction();
        BeanUtils.copyProperties(dto, skuFullReduction);
        save(skuFullReduction);
    }

    /**
     * 更新商品满减信息
     *
     * @param dto 商品满减信息更新
     */
    @Override
    public void updateSkuFullReduction(SkuFullReductionDto dto) {
        SkuFullReduction skuFullReduction =new SkuFullReduction();
        BeanUtils.copyProperties(dto, skuFullReduction);
        updateById(skuFullReduction);
    }

    /**
     * 删除|批量删除商品满减信息
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteSkuFullReduction(List<Long> ids) {
        removeByIds(ids);
    }
}