package iot.lidee.pay.core.convert.refund;

import iot.lidee.common.core.domain.PageResult;
import iot.lidee.common.utils.MapUtils;
import iot.lidee.common.utils.collection.CollectionUtils;
import iot.lidee.pay.api.api.refund.dto.PayRefundCreateReqDTO;
import iot.lidee.pay.api.api.refund.dto.PayRefundRespDTO;
import iot.lidee.pay.core.controller.admin.refund.vo.PayRefundDetailsRespVO;
import iot.lidee.pay.core.controller.admin.refund.vo.PayRefundExcelVO;
import iot.lidee.pay.core.controller.admin.refund.vo.PayRefundPageItemRespVO;
import iot.lidee.pay.core.domain.dataobject.app.PayApp;
import iot.lidee.pay.core.domain.dataobject.order.PayOrder;
import iot.lidee.pay.core.domain.dataobject.refund.PayRefund;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

import java.util.List;
import java.util.Map;

@Mapper
public interface PayRefundConvert {

    PayRefundConvert INSTANCE = Mappers.getMapper(PayRefundConvert.class);


    default PayRefundDetailsRespVO convert(PayRefund refund, PayApp app) {
        PayRefundDetailsRespVO respVO = convert(refund);
        if (app != null) {
            respVO.setAppName(app.getName());
        }
        return respVO;
    }
    PayRefundDetailsRespVO convert(PayRefund bean);
    PayRefundDetailsRespVO.Order convert(PayOrder bean);

    default PageResult<PayRefundPageItemRespVO> convertPage(PageResult<PayRefund> page, Map<Long, PayApp> appMap) {
        PageResult<PayRefundPageItemRespVO> result = convertPage(page);
        result.getList().forEach(order -> MapUtils.findAndThen(appMap, order.getAppId(), app -> order.setAppName(app.getName())));
        return result;
    }
    PageResult<PayRefundPageItemRespVO> convertPage(PageResult<PayRefund> page);

    PayRefund convert(PayRefundCreateReqDTO bean);

    PayRefundRespDTO convert02(PayRefund bean);

    default List<PayRefundExcelVO> convertList(List<PayRefund> list, Map<Long, PayApp> appMap) {
        return CollectionUtils.convertList(list, order -> {
            PayRefundExcelVO excelVO = convertExcel(order);
            MapUtils.findAndThen(appMap, order.getAppId(), app -> excelVO.setAppName(app.getName()));
            return excelVO;
        });
    }
    PayRefundExcelVO convertExcel(PayRefund bean);

}
