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.BrandDto;
import com.mall.product.domain.entity.Brand;
import com.mall.product.domain.vo.BrandVo;
import com.mall.product.mapper.BrandMapper;
import com.mall.product.service.BrandService;
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 BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements BrandService {

    /**
     * * 品牌 服务实现类
     *
     * @param pageParams 品牌分页查询page对象
     * @param dto        品牌分页查询对象
     * @return 查询分页品牌返回对象
     */
    @Override
    public PageResult<BrandVo> getBrandPage(Page<Brand> pageParams, BrandDto dto) {
        IPage<BrandVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加品牌
     *
     * @param dto 品牌添加
     */
    @Override
    public void addBrand(BrandDto dto) {
        Brand brand = new Brand();
        BeanUtils.copyProperties(dto, brand);
        save(brand);
    }

    /**
     * 更新品牌
     *
     * @param dto 品牌更新
     */
    @Override
    public void updateBrand(BrandDto dto) {
        Brand brand = new Brand();
        BeanUtils.copyProperties(dto, brand);
        updateById(brand);
    }

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