package com.mall.coupon.service.impl;

import com.mall.coupon.mapper.SeckillSkuRelationMapper;
import com.mall.coupon.service.SeckillSkuRelationService;
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.SeckillSkuRelationService;
import com.mall.coupon.domain.dto.SeckillSkuRelationDto;
import com.mall.coupon.domain.entity.SeckillSkuRelation;
import com.mall.coupon.domain.vo.SeckillSkuRelationVo;
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 SeckillSkuRelationServiceImpl extends ServiceImpl<SeckillSkuRelationMapper, SeckillSkuRelation> implements SeckillSkuRelationService {

    /**
     * * 秒杀活动商品关联 服务实现类
     *
     * @param pageParams 秒杀活动商品关联分页查询page对象
     * @param dto        秒杀活动商品关联分页查询对象
     * @return 查询分页秒杀活动商品关联返回对象
     */
    @Override
    public PageResult<SeckillSkuRelationVo> getSeckillSkuRelationPage(Page<SeckillSkuRelation> pageParams, SeckillSkuRelationDto dto) {
        IPage<SeckillSkuRelationVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加秒杀活动商品关联
     *
     * @param dto 秒杀活动商品关联添加
     */
    @Override
    public void addSeckillSkuRelation(SeckillSkuRelationDto dto) {
        SeckillSkuRelation seckillSkuRelation =new SeckillSkuRelation();
        BeanUtils.copyProperties(dto, seckillSkuRelation);
        save(seckillSkuRelation);
    }

    /**
     * 更新秒杀活动商品关联
     *
     * @param dto 秒杀活动商品关联更新
     */
    @Override
    public void updateSeckillSkuRelation(SeckillSkuRelationDto dto) {
        SeckillSkuRelation seckillSkuRelation =new SeckillSkuRelation();
        BeanUtils.copyProperties(dto, seckillSkuRelation);
        updateById(seckillSkuRelation);
    }

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