package com.qmth.boot.core.retrofit.utils;

import com.qmth.boot.core.retrofit.interfaces.SignatureProvider;
import com.qmth.boot.tools.signature.SignatureType;

/**
 * 调用方动态提供的签名信息，替代容器管理的静态配置
 */
public class SignatureInfo implements SignatureProvider {

    private SignatureType type;

    private String identity;

    private String secret;

    public SignatureInfo(SignatureType type, String identity, String secret) {
        this.type = type;
        this.identity = identity;
        this.secret = secret;
    }

    @Override
    public SignatureType getType() {
        return type;
    }

    @Override
    public String getIdentity() {
        return identity;
    }

    @Override
    public String getSecret() {
        return secret;
    }

    /**
     * 按照密钥类型创建签名信息
     *
     * @param accessKey
     * @param accessSecret
     * @return
     */
    public static SignatureInfo secret(String accessKey, String accessSecret) {
        return new SignatureInfo(SignatureType.SECRET, accessKey, accessSecret);
    }

    /**
     * 按照令牌类型创建签名信息
     *
     * @param session
     * @param token
     * @return
     */
    public static SignatureInfo token(String session, String token) {
        return new SignatureInfo(SignatureType.TOKEN, session, token);
    }
}
