package com.mall.coupon.service.impl;

import com.mall.coupon.mapper.SeckillSessionMapper;
import com.mall.coupon.service.SeckillSessionService;
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.SeckillSessionService;
import com.mall.coupon.domain.dto.SeckillSessionDto;
import com.mall.coupon.domain.entity.SeckillSession;
import com.mall.coupon.domain.vo.SeckillSessionVo;
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 SeckillSessionServiceImpl extends ServiceImpl<SeckillSessionMapper, SeckillSession> implements SeckillSessionService {

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

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

    /**
     * 添加秒杀活动场次
     *
     * @param dto 秒杀活动场次添加
     */
    @Override
    public void addSeckillSession(SeckillSessionDto dto) {
        SeckillSession seckillSession =new SeckillSession();
        BeanUtils.copyProperties(dto, seckillSession);
        save(seckillSession);
    }

    /**
     * 更新秒杀活动场次
     *
     * @param dto 秒杀活动场次更新
     */
    @Override
    public void updateSeckillSession(SeckillSessionDto dto) {
        SeckillSession seckillSession =new SeckillSession();
        BeanUtils.copyProperties(dto, seckillSession);
        updateById(seckillSession);
    }

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