package cn.estsh.i3plus.pojo.model.softswitch;

import cn.estsh.i3plus.pojo.base.annotation.XStreamCDATA;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.softswitch.bean.BsSuitRecord;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamAsAttribute;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import io.swagger.annotations.ApiParam;
import lombok.Data;

import java.io.Serializable;

/**
 * @Description :
 * @Reference :
 * @Author : wei.peng
 * @CreateDate : 19-7-25 下午3:29
 * @Modify:
 **/
@Data
@XStreamAlias("client")
public class SuitClientModel implements Serializable {

    private static final long serialVersionUID = -1073627855304303961L;
    /**
     * 适配套件代码
     */
    @XStreamAsAttribute
    private String suitCaseCode;

    @ApiParam(value = "套件类型(枚举)")
    @XStreamAsAttribute
    private Integer caseTypeId;

    @ApiParam(value = "适配命令(枚举)")
    private Integer actionId;

    /**
     * 调用方自定义标识
     */
    @XStreamAsAttribute
    private String suitSid;

    /**
     * 重试记录id
     */
    private Long retryRecordId;

    /**
     * 适配器信息
     */
    private BsSuitCaseModel suitCaseModel;

    /**
     * 适配记录
     */
    @XStreamOmitField
    private BsSuitRecord bsSuitRecord;

    /**
     * 适配结果信息
     */
    @XStreamCDATA
    private String suitMessage;

    /**
     * 适配发送报文信息
     */
    @XStreamCDATA
    private String suitSendMessage;

    /**
     * 请求来源
     */
    private Integer requestSource;

    /**
     * 适配方式
     */
    private Integer suitMethodId;

    public int getSuitMethodIdVal() {
        if (suitMethodId == null) {
            return -1;
        }
        return suitMethodId.intValue();
    }

    /**
     * 适配状态码
     */
    private String suitCaseStatusCode;
    /**
     * 认证令牌
     */
    private String token;
    /**
     * 认证结果
     */
    private Integer suitSslKeyResult;
    /**
     * 认证信息
     */
    private String suitSslKeyResultMessage;
    /**
     * 适配结果
     */
    private Integer suitResult;
    /**
     * 适配报文
     */
    @JsonIgnore
    @XStreamCDATA
    private Object suitResultMessage;

    private boolean isNeedRetry = false;

    public SuitClientModel() {
    }

    public SuitClientModel(Integer requestSource, BsSuitCaseModel suitCaseModel) {
        this.requestSource = requestSource;

        this.caseTypeId = suitCaseModel.getBsSuitCase().getCaseTypeId();
        this.actionId = suitCaseModel.getBsSuitCase().getSuitActionId();
        this.suitCaseCode = suitCaseModel.getBsSuitCase().getSuitCaseCode();
        this.suitCaseModel = suitCaseModel;

        // 设置默认
        this.suitCaseStatusCode = ResourceEnumUtil.MESSAGE.SUCCESS.getCode();
        // 设置默认
        this.suitSslKeyResult = CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue();
        // 设置默认
        this.suitResult = CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue();
    }

    public SuitClientModel(Integer requestSource, Integer suitMethodId, BsSuitCaseModel suitCaseModel) {
        this.requestSource = requestSource;
        this.suitMethodId = suitMethodId;

        this.caseTypeId = suitCaseModel.getBsSuitCase().getCaseTypeId();
        this.actionId = suitCaseModel.getBsSuitCase().getSuitActionId();
        this.suitCaseCode = suitCaseModel.getBsSuitCase().getSuitCaseCode();
        this.suitCaseModel = suitCaseModel;

        // 设置默认
        this.suitCaseStatusCode = ResourceEnumUtil.MESSAGE.SUCCESS.getCode();
        // 设置默认
        this.suitSslKeyResult = CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue();
        // 设置默认
        this.suitResult = CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue();
    }

    public SuitClientModel(SuitModel suitModel, BsSuitCaseModel suitCaseModel) {
        this.requestSource = suitModel.getRequestSource();
        this.suitSid = suitModel.getSuitSid();
        this.retryRecordId = suitModel.getRetryRecordId();

        this.caseTypeId = suitCaseModel.getBsSuitCase().getCaseTypeId();
        this.actionId = suitCaseModel.getBsSuitCase().getSuitActionId();
        this.suitCaseCode = suitCaseModel.getBsSuitCase().getSuitCaseCode();
        this.suitCaseModel = suitCaseModel;

        // 设置默认
        this.suitCaseStatusCode = ResourceEnumUtil.MESSAGE.SUCCESS.getCode();
        // 设置默认
        this.suitSslKeyResult = CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue();
        // 设置默认
        this.suitResult = CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue();
    }

}