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.CommentReplayDto;
import com.mall.product.domain.entity.CommentReplay;
import com.mall.product.domain.vo.CommentReplayVo;
import com.mall.product.mapper.CommentReplayMapper;
import com.mall.product.service.CommentReplayService;
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 CommentReplayServiceImpl extends ServiceImpl<CommentReplayMapper, CommentReplay> implements CommentReplayService {

    /**
     * * 商品评价回复关系 服务实现类
     *
     * @param pageParams 商品评价回复关系分页查询page对象
     * @param dto        商品评价回复关系分页查询对象
     * @return 查询分页商品评价回复关系返回对象
     */
    @Override
    public PageResult<CommentReplayVo> getCommentReplayPage(Page<CommentReplay> pageParams, CommentReplayDto dto) {
        IPage<CommentReplayVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加商品评价回复关系
     *
     * @param dto 商品评价回复关系添加
     */
    @Override
    public void addCommentReplay(CommentReplayDto dto) {
        CommentReplay commentReplay = new CommentReplay();
        BeanUtils.copyProperties(dto, commentReplay);
        save(commentReplay);
    }

    /**
     * 更新商品评价回复关系
     *
     * @param dto 商品评价回复关系更新
     */
    @Override
    public void updateCommentReplay(CommentReplayDto dto) {
        CommentReplay commentReplay = new CommentReplay();
        BeanUtils.copyProperties(dto, commentReplay);
        updateById(commentReplay);
    }

    /**
     * 删除|批量删除商品评价回复关系
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteCommentReplay(List<Long> ids) {
        removeByIds(ids);
    }
}