package com.kingdee.eas.custom.integration.apimgt.auth.model;

import com.kingdee.eas.custom.integration.apimgt.ApiRegistryBillInfo;
import com.kingdee.eas.custom.integration.apimgt.OpenPlatformAuthBillInfo;

/**
 * 认证结果
 */
public class AuthResult {

    /**
     * 认证是否成功
     */
    private boolean success;
    /**
     * 错误码
     */
    private int errorCode;
    /**
     * 错误信息
     */
    private String errorMessage;

    private OpenPlatformAuthBillInfo platform;
    /**
     * 接口信息
     */
    private ApiRegistryBillInfo api;

    /**
     * 私有构造函数
     */

    private AuthResult() {
    }

    /**
     * 认证成功
     *
     * @param platform 平台信息
     * @param api      接口信息
     * @return 认证结果
     */
    public static AuthResult success(
            OpenPlatformAuthBillInfo platform,
            ApiRegistryBillInfo api) {
        AuthResult result = new AuthResult();
        result.success = true;
        result.platform = platform;
        result.api = api;
        return result;
    }

    /**
     * 认证失败
     *
     * @param errorCode 错误码
     * @return 认证结果
     */
    public static AuthResult failure(AuthErrorCode errorCode) {
        return failure(errorCode.getCode(), errorCode.getMessage());
    }

    /**
     * 认证失败
     *
     * @param errorCode    错误码
     * @param errorMessage 错误信息
     * @return 认证结果
     */
    public static AuthResult failure(int errorCode, String errorMessage) {
        AuthResult result = new AuthResult();
        result.success = false;
        result.errorCode = errorCode;
        result.errorMessage = errorMessage;
        return result;
    }

    public boolean isSuccess() {
        return success;
    }

    public int getErrorCode() {
        return errorCode;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public OpenPlatformAuthBillInfo getPlatform() {
        return platform;
    }

    public ApiRegistryBillInfo getApi() {
        return api;
    }
}
