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.CategoryBrandRelationDto;
import com.mall.product.domain.entity.CategoryBrandRelation;
import com.mall.product.domain.vo.CategoryBrandRelationVo;
import com.mall.product.mapper.CategoryBrandRelationMapper;
import com.mall.product.service.CategoryBrandRelationService;
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 CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationMapper, CategoryBrandRelation> implements CategoryBrandRelationService {

    /**
     * * 品牌分类关联 服务实现类
     *
     * @param pageParams 品牌分类关联分页查询page对象
     * @param dto        品牌分类关联分页查询对象
     * @return 查询分页品牌分类关联返回对象
     */
    @Override
    public PageResult<CategoryBrandRelationVo> getCategoryBrandRelationPage(Page<CategoryBrandRelation> pageParams, CategoryBrandRelationDto dto) {
        IPage<CategoryBrandRelationVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加品牌分类关联
     *
     * @param dto 品牌分类关联添加
     */
    @Override
    public void addCategoryBrandRelation(CategoryBrandRelationDto dto) {
        CategoryBrandRelation categoryBrandRelation = new CategoryBrandRelation();
        BeanUtils.copyProperties(dto, categoryBrandRelation);
        save(categoryBrandRelation);
    }

    /**
     * 更新品牌分类关联
     *
     * @param dto 品牌分类关联更新
     */
    @Override
    public void updateCategoryBrandRelation(CategoryBrandRelationDto dto) {
        CategoryBrandRelation categoryBrandRelation = new CategoryBrandRelation();
        BeanUtils.copyProperties(dto, categoryBrandRelation);
        updateById(categoryBrandRelation);
    }

    /**
     * 删除|批量删除品牌分类关联
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteCategoryBrandRelation(List<Long> ids) {
        removeByIds(ids);
    }
}