package com.oguerreiro.resilient.security.saml2;

import java.util.List;
import java.util.Map;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
@ConfigurationProperties(prefix = "resilient.security.saml2")
public class ResilientSaml2Properties {

  private boolean enabled;
  private String idpId;
  private String baseUrl;
  private String successUrl;
  private String failureUrl;
  private RelyingParty relyingparty;

  public static class RelyingParty {
    private Map<String, Registration> registration;

    public Map<String, Registration> getRegistration() {
      return registration;
    }

    public void setRegistration(Map<String, Registration> registration) {
      this.registration = registration;
    }
  }

  public static class Registration {
    private AssertingParty assertingparty;
    private Signing signing;

    public AssertingParty getAssertingparty() {
      return assertingparty;
    }

    public void setAssertingparty(AssertingParty assertingparty) {
      this.assertingparty = assertingparty;
    }

    public Signing getSigning() {
      return signing;
    }

    public void setSigning(Signing signing) {
      this.signing = signing;
    }
  }

  public static class AssertingParty {
    private String entityId;
    private UrlConfig singleSignOn;
    private UrlConfig singleLogout;
    private Verification verification;
    private boolean wantAuthnSigned;
    private boolean wantAssertionSigned;

    // Attributes
    private Map<String, String> attributes;

    // Attributes defaults
    private Map<String, String> defaults;

    // Getters and Setters

    public Map<String, String> getDefaults() {
      return defaults;
    }

    public void setDefaults(Map<String, String> defaults) {
      this.defaults = defaults;
    }

    public String getEntityId() {
      return entityId;
    }

    public Map<String, String> getAttributes() {
      return attributes;
    }

    public void setAttributes(Map<String, String> attributes) {
      this.attributes = attributes;
    }

    public void setEntityId(String entityId) {
      this.entityId = entityId;
    }

    public UrlConfig getSingleSignOn() {
      return singleSignOn;
    }

    public void setSingleSignOn(UrlConfig singleSignOn) {
      this.singleSignOn = singleSignOn;
    }

    public UrlConfig getSingleLogout() {
      return singleLogout;
    }

    public void setSingleLogout(UrlConfig singleLogout) {
      this.singleLogout = singleLogout;
    }

    public Verification getVerification() {
      return verification;
    }

    public void setVerification(Verification verification) {
      this.verification = verification;
    }

    public boolean isWantAuthnSigned() {
      return wantAuthnSigned;
    }

    public void setWantAuthnSigned(boolean wantAuthnSigned) {
      this.wantAuthnSigned = wantAuthnSigned;
    }

    public boolean isWantAssertionSigned() {
      return wantAssertionSigned;
    }

    public void setWantAssertionSigned(boolean wantAssertionSigned) {
      this.wantAssertionSigned = wantAssertionSigned;
    }
  }

  public static class Signing {
    private List<Credential> credentials;

    public List<Credential> getCredentials() {
      return credentials;
    }

    public void setCredentials(List<Credential> credentials) {
      this.credentials = credentials;
    }

    public static class Credential {
      private String privateKeyLocation;
      private String certificateLocation;

      public String getPrivateKeyLocation() {
        return privateKeyLocation;
      }

      public void setPrivateKeyLocation(String privateKeyLocation) {
        this.privateKeyLocation = privateKeyLocation;
      }

      public String getCertificateLocation() {
        return certificateLocation;
      }

      public void setCertificateLocation(String certificateLocation) {
        this.certificateLocation = certificateLocation;
      }
    }
  }

  public static class Verification {
    private List<Credential> credentials;

    public List<Credential> getCredentials() {
      return credentials;
    }

    public void setCredentials(List<Credential> credentials) {
      this.credentials = credentials;
    }

    public static class Credential {
      private String certificateLocation;

      public String getCertificateLocation() {
        return certificateLocation;
      }

      public void setCertificateLocation(String certificateLocation) {
        this.certificateLocation = certificateLocation;
      }
    }
  }

  public static class UrlConfig {
    private String url;
    // Add this map for query-parameters
    private Map<String, String> queryParameters;

    public String getUrl() {
      return url;
    }

    public void setUrl(String url) {
      this.url = url;
    }

    public Map<String, String> getQueryParameters() {
      return queryParameters;
    }

    public void setQueryParameters(Map<String, String> queryParameters) {
      this.queryParameters = queryParameters;
    }
  }

  // Root-level Getters/Setters

  public boolean isEnabled() {
    return enabled;
  }

  public void setEnabled(boolean enabled) {
    this.enabled = enabled;
  }

  public String getIdpId() {
    return idpId;
  }

  public void setIdpId(String idpId) {
    this.idpId = idpId;
  }

  public String getBaseUrl() {
    return baseUrl;
  }

  public void setBaseUrl(String baseUrl) {
    this.baseUrl = baseUrl;
  }

  public String getSuccessUrl() {
    return successUrl;
  }

  public void setSuccessUrl(String successUrl) {
    this.successUrl = successUrl;
  }

  public String getFailureUrl() {
    return failureUrl;
  }

  public void setFailureUrl(String failureUrl) {
    this.failureUrl = failureUrl;
  }

  public RelyingParty getRelyingparty() {
    return relyingparty;
  }

  public void setRelyingparty(RelyingParty relyingparty) {
    this.relyingparty = relyingparty;
  }
}
