package com.seer.teach.pay.app.client.convert;

import com.seer.teach.pay.app.client.dto.PayOrderReqDTO;
import com.seer.teach.pay.app.client.dto.RefundNotificationRespDTO;
import com.seer.teach.pay.app.client.wechat.core.resp.WechatPrepayTransactionResp;
import com.seer.teach.pay.app.client.dto.PayOrderCallBackRespDTO;
import com.seer.teach.pay.app.client.dto.PayOrderRespDTO;
import com.seer.teach.pay.app.pay.controller.req.OrderPayReq;
import com.seer.teach.pay.app.refund.service.dto.RefundResultDTO;
import com.seer.teach.pay.dto.RefundSubmitRespDTO;
import com.seer.teach.pay.entity.PayOrderEntity;
import com.seer.teach.pay.entity.RefundOrderEntity;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

@Mapper
public interface PayClientConvert {

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

    WechatPrepayTransactionResp convert(PrepayWithRequestPaymentResponse prepayWithRequestPaymentResponse);

    @Mapping(source = "outTradeNo", target = "refundOrderSn")
    @Mapping(source = "responseJson", target = "refundResJson")
    RefundResultDTO convertRefundNotificationResp2Result(RefundNotificationRespDTO refundNotificationRespDTO);

    PayOrderRespDTO convert(PayOrderCallBackRespDTO payOrderCallBackRespDTO);

    default RefundResultDTO convertRefundSubmitResp2Result(RefundSubmitRespDTO refundSubmitResp){
        RefundResultDTO refundResultDTO = new RefundResultDTO();
        refundResultDTO.setRefundResJson(refundSubmitResp.getRefundResJson());
        refundResultDTO.setRefundOrderSn(refundSubmitResp.getRefundOrderSn());
        refundResultDTO.setStatus(refundSubmitResp.getStatus());
        refundResultDTO.setSuccessTime(refundSubmitResp.getSuccessTime());
        refundResultDTO.setCurrency(refundSubmitResp.getCurrency());
        refundResultDTO.setTransactionId(refundSubmitResp.getTransactionId());
        refundResultDTO.setRefundAmount(refundSubmitResp.getRefundAmount());
        refundResultDTO.setRefundId(refundSubmitResp.getRefundId());

        return refundResultDTO;
    }

    RefundOrderEntity convert(RefundResultDTO refundResultDTO);

    /**
     * 订单支付请求参数转换
     * @param payOrderEntity
     * @param payReq
     * @return PayOrderReqDTO
     */
    @Mapping(source = "payOrderEntity.subject", target = "description")
    @Mapping(source = "payReq.channelCode", target = "channelCode")
    @Mapping(source = "payOrderEntity.merchantOrderSn", target = "merchantOrderSn")
    @Mapping(source = "payOrderEntity.id", target = "parOrderId")
    @Mapping(source = "payOrderEntity.orderSn", target = "payOrderSn")
    PayOrderReqDTO convert2PayOrderReqDTO(PayOrderEntity payOrderEntity,OrderPayReq payReq);

}