package com.younike.hlpay.dto;

import com.google.common.collect.ImmutableSet;
import com.younike.hlpay.constant.HeliPayContants;
import com.younike.hlpay.util.DesUtils;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

import java.util.Set;

/**
 * 4.4 App(SDK)预下单接口
 */
@Setter
@Getter
@ToString
public class SDKCreateOrderVo {

    private String P1_bizType;
    private String P2_orderId;
    private String P3_customerNumber;
    private String P4_payType;
    private String P5_orderAmount;
    private String P6_currency;
    private String P7_authcode;
    private String P8_appType;
    private String P9_notifyUrl;
    private String P10_successToUrl;
    private String P11_orderIp;
    private String P12_goodsName;
    private String P13_goodsDetail;
    private String P14_desc;

    private String P20_marketingRule;
    //不签名
    private String P15_subMerchantId;
    //不签名
    private String ruleJson;
    //不签名
    private String splitBillType;
    private String sign;

    public void setRuleJson(String ruleJson) {
        System.out.println("ruleJson 明文 result:" + ruleJson);
        if (StringUtils.isNotBlank(ruleJson)) {
            try {
                ruleJson = DesUtils.encode(HeliPayContants.DES_APPPAY, ruleJson);
            } catch (Exception e) {
                System.out.println("error:" + e.getMessage());
            }
            System.out.println("ruleJson 3des result:" + ruleJson);
        }
        this.ruleJson = ruleJson;
    }

    public void setP18MarketingRule(String P18marketingRule) {
        System.out.println("P18marketingRule 明文 result:" + P18marketingRule);
        if (StringUtils.isNotBlank(P18marketingRule)) {
            try {
                P18marketingRule = DesUtils.encode(HeliPayContants.DES_APPPAY, P18marketingRule);
            } catch (Exception e) {
                System.out.println("error:" + e.getMessage());
            }
            System.out.println("p23MarketingRule 3des result:" + P18marketingRule);
        }
        this.P20_marketingRule = P18marketingRule;
    }

    /**
     * 需要加签的属性参数,要求加签的参数空值也签名
     * 看接口文档
     */
    public static final Set<String> NEED_SIGN_PARAMS = ImmutableSet.of("P1_bizType", "P2_orderId", "P3_customerNumber",
            "P4_payType", "P5_orderAmount", "P6_currency", "P7_authcode", "P8_appType", "P9_notifyUrl", "P10_successToUrl",
            "P11_orderIp", "P12_goodsName", "P13_goodsDetail", "P14_desc");
}
