package com.mall.coupon.service.impl;

import com.mall.coupon.mapper.HomeAdvMapper;
import com.mall.coupon.service.HomeAdvService;
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.HomeAdvService;
import com.mall.coupon.domain.dto.HomeAdvDto;
import com.mall.coupon.domain.entity.HomeAdv;
import com.mall.coupon.domain.vo.HomeAdvVo;
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 HomeAdvServiceImpl extends ServiceImpl<HomeAdvMapper, HomeAdv> implements HomeAdvService {

    /**
     * * 首页轮播广告 服务实现类
     *
     * @param pageParams 首页轮播广告分页查询page对象
     * @param dto        首页轮播广告分页查询对象
     * @return 查询分页首页轮播广告返回对象
     */
    @Override
    public PageResult<HomeAdvVo> getHomeAdvPage(Page<HomeAdv> pageParams, HomeAdvDto dto) {
        IPage<HomeAdvVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加首页轮播广告
     *
     * @param dto 首页轮播广告添加
     */
    @Override
    public void addHomeAdv(HomeAdvDto dto) {
        HomeAdv homeAdv =new HomeAdv();
        BeanUtils.copyProperties(dto, homeAdv);
        save(homeAdv);
    }

    /**
     * 更新首页轮播广告
     *
     * @param dto 首页轮播广告更新
     */
    @Override
    public void updateHomeAdv(HomeAdvDto dto) {
        HomeAdv homeAdv =new HomeAdv();
        BeanUtils.copyProperties(dto, homeAdv);
        updateById(homeAdv);
    }

    /**
     * 删除|批量删除首页轮播广告
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteHomeAdv(List<Long> ids) {
        removeByIds(ids);
    }
}