package com.mall.order.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.order.domain.dto.RefundInfoDto;
import com.mall.order.domain.entity.RefundInfo;
import com.mall.order.domain.vo.RefundInfoVo;
import com.mall.order.mapper.RefundInfoMapper;
import com.mall.order.service.RefundInfoService;
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-05 18:54:06
 */
@Service
@Transactional
public class RefundInfoServiceImpl extends ServiceImpl<RefundInfoMapper, RefundInfo> implements RefundInfoService {

    /**
     * * 退款信息 服务实现类
     *
     * @param pageParams 退款信息分页查询page对象
     * @param dto        退款信息分页查询对象
     * @return 查询分页退款信息返回对象
     */
    @Override
    public PageResult<RefundInfoVo> getRefundInfoPage(Page<RefundInfo> pageParams, RefundInfoDto dto) {
        IPage<RefundInfoVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加退款信息
     *
     * @param dto 退款信息添加
     */
    @Override
    public void addRefundInfo(RefundInfoDto dto) {
        RefundInfo refundInfo = new RefundInfo();
        BeanUtils.copyProperties(dto, refundInfo);
        save(refundInfo);
    }

    /**
     * 更新退款信息
     *
     * @param dto 退款信息更新
     */
    @Override
    public void updateRefundInfo(RefundInfoDto dto) {
        RefundInfo refundInfo = new RefundInfo();
        BeanUtils.copyProperties(dto, refundInfo);
        updateById(refundInfo);
    }

    /**
     * 删除|批量删除退款信息
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteRefundInfo(List<Long> ids) {
        removeByIds(ids);
    }
}