package com.mall.coupon.service.impl;

import com.mall.coupon.mapper.SeckillPromotionMapper;
import com.mall.coupon.service.SeckillPromotionService;
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.SeckillPromotionService;
import com.mall.coupon.domain.dto.SeckillPromotionDto;
import com.mall.coupon.domain.entity.SeckillPromotion;
import com.mall.coupon.domain.vo.SeckillPromotionVo;
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 SeckillPromotionServiceImpl extends ServiceImpl<SeckillPromotionMapper, SeckillPromotion> implements SeckillPromotionService {

    /**
     * * 秒杀活动 服务实现类
     *
     * @param pageParams 秒杀活动分页查询page对象
     * @param dto        秒杀活动分页查询对象
     * @return 查询分页秒杀活动返回对象
     */
    @Override
    public PageResult<SeckillPromotionVo> getSeckillPromotionPage(Page<SeckillPromotion> pageParams, SeckillPromotionDto dto) {
        IPage<SeckillPromotionVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加秒杀活动
     *
     * @param dto 秒杀活动添加
     */
    @Override
    public void addSeckillPromotion(SeckillPromotionDto dto) {
        SeckillPromotion seckillPromotion =new SeckillPromotion();
        BeanUtils.copyProperties(dto, seckillPromotion);
        save(seckillPromotion);
    }

    /**
     * 更新秒杀活动
     *
     * @param dto 秒杀活动更新
     */
    @Override
    public void updateSeckillPromotion(SeckillPromotionDto dto) {
        SeckillPromotion seckillPromotion =new SeckillPromotion();
        BeanUtils.copyProperties(dto, seckillPromotion);
        updateById(seckillPromotion);
    }

    /**
     * 删除|批量删除秒杀活动
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteSeckillPromotion(List<Long> ids) {
        removeByIds(ids);
    }
}