package com.zsElectric.boot.thirdParty.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;

/**
 * query_token 接口响应参数 (data加密前的内容)
 *
 * @author wzq
 */
@Data
public class QueryTokenResponseData implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 运营商标识
     */
    @JsonProperty("operatorId")
    private String operatorId;

    /**
     * 操作结果标识
     * 0: 成功
     * 1: 失败
     */
    @JsonProperty("resultStatus")
    private Integer resultStatus;

    /**
     * 访问令牌 - token令牌
     */
    @JsonProperty("accessToken")
    private String accessToken;

    /**
     * token有效期 - 单位秒
     */
    @JsonProperty("tokenExpirationTime")
    private Integer tokenExpirationTime;

    /**
     * 失败原因
     * 0: 无
     * 1: operatorId无效
     */
    @JsonProperty("failReason")
    private Integer failReason;

    /**
     * 创建成功响应数据
     */
    public static QueryTokenResponseData success(String operatorId, String accessToken, Integer expirationTime) {
        QueryTokenResponseData data = new QueryTokenResponseData();
        data.setOperatorId(operatorId);
        data.setResultStatus(0);
        data.setAccessToken(accessToken);
        data.setTokenExpirationTime(expirationTime);
        data.setFailReason(0);
        return data;
    }

    /**
     * 创建失败响应数据
     */
    public static QueryTokenResponseData fail(String operatorId, Integer failReason) {
        QueryTokenResponseData data = new QueryTokenResponseData();
        data.setOperatorId(operatorId);
        data.setResultStatus(1);
        data.setAccessToken("");
        data.setTokenExpirationTime(0);
        data.setFailReason(failReason);
        return data;
    }
}
