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.AttrGroupDto;
import com.mall.product.domain.entity.AttrGroup;
import com.mall.product.domain.vo.AttrGroupVo;
import com.mall.product.mapper.AttrGroupMapper;
import com.mall.product.service.AttrGroupService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 属性分组 服务实现类
 * </p>
 *
 * @author Bunny
 * @since 2025-07-04 14:05:53
 */
@Service
@Transactional
public class AttrGroupServiceImpl extends ServiceImpl<AttrGroupMapper, AttrGroup> implements AttrGroupService {

    /**
     * * 属性分组 服务实现类
     *
     * @param pageParams 属性分组分页查询page对象
     * @param dto        属性分组分页查询对象
     * @return 查询分页属性分组返回对象
     */
    @Override
    public PageResult<AttrGroupVo> getAttrGroupPage(Page<AttrGroup> pageParams, AttrGroupDto dto) {
        IPage<AttrGroupVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加属性分组
     *
     * @param dto 属性分组添加
     */
    @Override
    public void addAttrGroup(AttrGroupDto dto) {
        AttrGroup attrGroup = new AttrGroup();
        BeanUtils.copyProperties(dto, attrGroup);
        save(attrGroup);
    }

    /**
     * 更新属性分组
     *
     * @param dto 属性分组更新
     */
    @Override
    public void updateAttrGroup(AttrGroupDto dto) {
        AttrGroup attrGroup = new AttrGroup();
        BeanUtils.copyProperties(dto, attrGroup);
        updateById(attrGroup);
    }

    /**
     * 删除|批量删除属性分组
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteAttrGroup(List<Long> ids) {
        removeByIds(ids);
    }
}