package com.jeequan.jeepay.thirdparty.channel.sxfpay.model;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.util.Date;

/**
 * TODO
 *
 * @author crystal
 * @date 2024/2/27 10:46
 */
@Setter
@Getter
public class ReqEntity {

    public static final String DEFAULT_VERSION = "1.0";

    public static final String DEFAULT_SIGN_TYPE = "RSA";

    private String orgId;

    private String reqId;

    private String version;

    private String timestamp;

    private JSONObject reqData;

    private String signType;

    private String sign;

    public ReqEntity(String orgId, JSONObject reqData) {
        this.orgId = orgId;
        this.reqId = IdUtil.fastUUID().replace("-", "");
        this.version = DEFAULT_VERSION;
        this.timestamp = DateFormatUtils.format(new Date(), "yyyyMMddHHmmss");
        this.reqData = reqData;
        this.signType = DEFAULT_SIGN_TYPE;
    }

    @JSONField(serialize = false)
    public String getSignContent() {
        return "orgId" + "=" + orgId + "&" +
                "reqData" + "=" + reqData + "&" +
                "reqId" + "=" + reqId + "&" +
                "signType" + "=" + signType + "&" +
                "timestamp" + "=" + timestamp + "&" +
                "version" + "=" + version;

    }
}
