package ru.micord.ervu.security.esia.config;

import java.util.Arrays;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @author Eduard Tihomirov
 */
@Component
public class EsiaConfig {

  @Value("${esia.scopes}")
  private String esiaScopes;

  @Value("${esia.base.uri}")
  private String esiaBaseUri;

  @Value("${esia.client.id}")
  private String clientId;

  @Value("${esia.redirect.url}")
  private String redirectUrl;

  @Value("${sign.url}")
  private String signUrl;

  @Value("${esia.client.cert.hash}")
  private String clientCertHash;

  @Value("${esia.request.timeout:60}")
  private long requestTimeout;

  @Value("${esia.connection.timeout:30}")
  private long connectionTimeout;

  @Value("${esia.logout.url:idp/ext/Logout}")
  private String esiaLogoutUrl;

  @Value("${esia.code.url:aas/oauth2/v2/ac}")
  private String esiaCodeUrl;

  @Value("${esia.token.url:aas/oauth2/v3/te}")
  private String esiaTokenUrl;

  public String getEsiaScopes() {
    String[] scopeItems = esiaScopes.split(",");
    return String.join(" ", Arrays.stream(scopeItems).map(String::trim).toArray(String[]::new));
  }

  public String getClientId() {
    return clientId;
  }

  public String getRedirectUrl() {
    return redirectUrl;
  }

  public String getEsiaBaseUri() {
    return esiaBaseUri;
  }

  public String getSignUrl() {
    return signUrl;
  }

  public String getClientCertHash() {return clientCertHash;}

  public long getRequestTimeout() {
    return requestTimeout;
  }

  public long getConnectionTimeout() {
    return connectionTimeout;
  }

  public String getEsiaLogoutUrl() {
    return esiaLogoutUrl;
  }

  public String getEsiaCodeUrl() {
    return esiaCodeUrl;
  }

  public String getEsiaTokenUrl() {
    return esiaTokenUrl;
  }
}
