package cz.senslog.connector.fetch.azure.auth;

import java.time.LocalDateTime;

import static cz.senslog.connector.tools.json.BasicJson.objectToJson;

/**
 * The class {@code AzureAuthorizationInfo} represents a transfer object of authorization information.
 *
 * @author Lukas Cerny
 * @version 1.0
 * @since 1.0
 */
class AzureAuthorizationInfo {

    /** String hash token. */
    private String accessToken;

    /** Time when the token expires. */
    private LocalDateTime expires;

    /**
     * Check if the token is valid and can be used for authorization.
     * @return true/false if token expires or not.
     */
    public boolean isAuthorized() {

        if (accessToken == null || expires == null) {
            return false;
        }

        if (expires.isBefore(LocalDateTime.now())) {
            return false;
        }

        return true;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public LocalDateTime getExpires() {
       return expires;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public void setExpires(LocalDateTime expires) {
        this.expires = expires;
    }

    @Override
    public String toString() {
        return objectToJson(this);
    }
}
