package com.mall.product.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.mall.common.domain.vo.result.PageResult;
import com.mall.product.domain.dto.SpuImagesDto;
import com.mall.product.domain.entity.SpuImages;
import com.mall.product.domain.vo.SpuImagesVo;
import com.mall.product.mapper.SpuImagesMapper;
import com.mall.product.service.SpuImagesService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * spu图片 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2025-07-04 14:05:53
 */
@Service
@Transactional
public class SpuImagesServiceImpl extends ServiceImpl<SpuImagesMapper, SpuImages> implements SpuImagesService {

    /**
     * * spu图片 服务实现类
     *
     * @param pageParams spu图片分页查询page对象
     * @param dto        spu图片分页查询对象
     * @return 查询分页spu图片返回对象
     */
    @Override
    public PageResult<SpuImagesVo> getSpuImagesPage(Page<SpuImages> pageParams, SpuImagesDto dto) {
        IPage<SpuImagesVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加spu图片
     *
     * @param dto spu图片添加
     */
    @Override
    public void addSpuImages(SpuImagesDto dto) {
        SpuImages spuImages = new SpuImages();
        BeanUtils.copyProperties(dto, spuImages);
        save(spuImages);
    }

    /**
     * 更新spu图片
     *
     * @param dto spu图片更新
     */
    @Override
    public void updateSpuImages(SpuImagesDto dto) {
        SpuImages spuImages = new SpuImages();
        BeanUtils.copyProperties(dto, spuImages);
        updateById(spuImages);
    }

    /**
     * 删除|批量删除spu图片
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteSpuImages(List<Long> ids) {
        removeByIds(ids);
    }
}