package com.red.circle.order.domain.order;

import com.google.gson.Gson;
import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * payermax 支付返回回调响应类
 * 参考地址：https://docs.payermax.com/api.html?docName=New%20Version&docVer=v1.0&docLang=cn#/paths/collectResultNotifyUrl/post
 */

@Data
public class PayerMaxReceivePaymentNotice {
    private static final Logger log = LoggerFactory.getLogger(PayerMaxReceivePaymentNotice.class);
    private static final long serialVersionUID = 1L;

    /*{"appId":"d084f1170edb41e5953ca4858eb84822","code":"APPLY_SUCCESS",
    "data":{"reference":"","country":"SA","totalAmount":38,"channelNo":"UPC886100172181273254422009422",
    "outTradeNo":"1816040288158875650","completeTime":"2024-07-24T09:18:52.695Z",
    "currency":"SAR","tradeToken":"T2024072409886101019717",
    "paymentDetails":[{"cardInfo":{"cardOrg":"MADA","country":"SA","cardIdentifierNo":"529741******5689",
    "cardIdentifierName":"William*******"},"paymentMethodType":"CARD"}],
    "thirdChannelNo":"ea37864b-c77a-4258-8297-934980a8c8f9","status":"SUCCESS"},
    "keyVersion":"1","merchantNo":"SDP01010114445337","msg":
    "Success.","notifyTime":"2024-07-24T09:18:52.753Z","notifyType":"PAYMENT"}*/

    private Data data;

    private String keyVersion;
    private String merchantNo;
    private String msg;
    private String appId;
    private String code;
    private String notifyTime;
    private String notifyType;

    @lombok.Data
    public static class Data {
        private String reference;
        private String country;
        private Integer totalAmount;
        private String channelNo;
        private String outTradeNo;
        private String completeTime;
        private String currency;
        private String tradeToken;
        private List<PaymentDetails> paymentDetails;
        private MerFee fees;
        private String thirdChannelNo;
        private String status;
    }

    @lombok.Data
    public static class PaymentDetails {
        private CardInfo cardInfo;
        private String paymentMethodType;
    }

    @lombok.Data
    public static class MerFee {
        private String url;
        private String amount;
        private String currency;
    }

    @lombok.Data
    public static class CardInfo {
        private String cardOrg;
        private String country;
        private String cardIdentifierNo;
        private String cardIdentifierName;
    }

    public static PayerMaxReceivePaymentNotice serializable(String json) {
        return new Gson().fromJson(json, PayerMaxReceivePaymentNotice.class);
    }
}
