package com.mall.coupon.service.impl;

import com.mall.coupon.mapper.SeckillSkuNoticeMapper;
import com.mall.coupon.service.SeckillSkuNoticeService;
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.SeckillSkuNoticeService;
import com.mall.coupon.domain.dto.SeckillSkuNoticeDto;
import com.mall.coupon.domain.entity.SeckillSkuNotice;
import com.mall.coupon.domain.vo.SeckillSkuNoticeVo;
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 SeckillSkuNoticeServiceImpl extends ServiceImpl<SeckillSkuNoticeMapper, SeckillSkuNotice> implements SeckillSkuNoticeService {

    /**
     * * 秒杀商品通知订阅 服务实现类
     *
     * @param pageParams 秒杀商品通知订阅分页查询page对象
     * @param dto        秒杀商品通知订阅分页查询对象
     * @return 查询分页秒杀商品通知订阅返回对象
     */
    @Override
    public PageResult<SeckillSkuNoticeVo> getSeckillSkuNoticePage(Page<SeckillSkuNotice> pageParams, SeckillSkuNoticeDto dto) {
        IPage<SeckillSkuNoticeVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加秒杀商品通知订阅
     *
     * @param dto 秒杀商品通知订阅添加
     */
    @Override
    public void addSeckillSkuNotice(SeckillSkuNoticeDto dto) {
        SeckillSkuNotice seckillSkuNotice =new SeckillSkuNotice();
        BeanUtils.copyProperties(dto, seckillSkuNotice);
        save(seckillSkuNotice);
    }

    /**
     * 更新秒杀商品通知订阅
     *
     * @param dto 秒杀商品通知订阅更新
     */
    @Override
    public void updateSeckillSkuNotice(SeckillSkuNoticeDto dto) {
        SeckillSkuNotice seckillSkuNotice =new SeckillSkuNotice();
        BeanUtils.copyProperties(dto, seckillSkuNotice);
        updateById(seckillSkuNotice);
    }

    /**
     * 删除|批量删除秒杀商品通知订阅
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteSeckillSkuNotice(List<Long> ids) {
        removeByIds(ids);
    }
}