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.OrderReturnReasonDto;
import com.mall.order.domain.entity.OrderReturnReason;
import com.mall.order.domain.vo.OrderReturnReasonVo;
import com.mall.order.mapper.OrderReturnReasonMapper;
import com.mall.order.service.OrderReturnReasonService;
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 OrderReturnReasonServiceImpl extends ServiceImpl<OrderReturnReasonMapper, OrderReturnReason> implements OrderReturnReasonService {

    /**
     * * 退货原因 服务实现类
     *
     * @param pageParams 退货原因分页查询page对象
     * @param dto        退货原因分页查询对象
     * @return 查询分页退货原因返回对象
     */
    @Override
    public PageResult<OrderReturnReasonVo> getOrderReturnReasonPage(Page<OrderReturnReason> pageParams, OrderReturnReasonDto dto) {
        IPage<OrderReturnReasonVo> page = baseMapper.selectListByPage(pageParams, dto);

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

    /**
     * 添加退货原因
     *
     * @param dto 退货原因添加
     */
    @Override
    public void addOrderReturnReason(OrderReturnReasonDto dto) {
        OrderReturnReason orderReturnReason = new OrderReturnReason();
        BeanUtils.copyProperties(dto, orderReturnReason);
        save(orderReturnReason);
    }

    /**
     * 更新退货原因
     *
     * @param dto 退货原因更新
     */
    @Override
    public void updateOrderReturnReason(OrderReturnReasonDto dto) {
        OrderReturnReason orderReturnReason = new OrderReturnReason();
        BeanUtils.copyProperties(dto, orderReturnReason);
        updateById(orderReturnReason);
    }

    /**
     * 删除|批量删除退货原因
     *
     * @param ids 删除id列表
     */
    @Override
    public void deleteOrderReturnReason(List<Long> ids) {
        removeByIds(ids);
    }
}