package com.airlock.iam.saml2.domain.model.idp.logout;

import com.airlock.iam.base.api.domain.model.mapification.Mapifiable;
import com.airlock.iam.base.api.domain.model.mapification.MapifiedValues;
import com.airlock.iam.base.domain.model.mapification.MapifiedValuesBuilder;
import com.airlock.iam.core.domain.model.http.HttpRequestMethod;
import com.airlock.iam.saml2.domain.model.Saml2RelayState;
import com.airlock.iam.saml2.domain.model.Saml2Signature;
import com.airlock.iam.saml2.domain.model.Saml2SignatureAlgorithm;
import com.airlock.iam.saml2.domain.model.idp.Saml2RequestParameter;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
import lombok.NonNull;

public final class Saml2SpInitiatedSloAttributes implements Mapifiable {
   private static final String SLO_REQUEST_KEY = "samlSloRequest";
   private static final String HTTP_METHOD_KEY = "httpMethod";
   private static final String REQUEST_URI_KEY = "requestUri";
   private static final String QUERY_KEY = "queryString";
   private static final String RELAY_STATE_KEY = "relayState";
   private static final String SIG_ALG_KEY = "sigAlg";
   private static final String SIGNATURE_KEY = "signature";
   @NonNull
   private final Saml2RequestParameter samlSloRequest;
   @NonNull
   private final HttpRequestMethod httpMethod;
   @NonNull
   private final String requestUri;
   @NonNull
   private final Optional<String> queryString;
   @NonNull
   private final Optional<Saml2RelayState> relayState;
   @NonNull
   private final Optional<Saml2SignatureAlgorithm> signatureAlgorithm;
   @NonNull
   private final Optional<Saml2Signature> signature;

   @Override
   public MapifiedValues mapify() {
      return MapifiedValuesBuilder.mapifiedValues()
         .put("samlSloRequest", this.samlSloRequest.value())
         .put("httpMethod", this.httpMethod.name())
         .put("requestUri", this.requestUri)
         .putIfPresent("queryString", this.queryString)
         .putIfPresent("relayState", this.relayState.map(Saml2RelayState::value))
         .putIfPresent("sigAlg", this.signatureAlgorithm.map(Saml2SignatureAlgorithm::value))
         .putIfPresent("signature", this.signature.map(Saml2Signature::value))
         .build();
   }

   public static Saml2SpInitiatedSloAttributes demapify(MapifiedValues values) {
      return builder()
         .samlSloRequest(values.simpleValue("samlSloRequest", Saml2RequestParameter::samlRequest))
         .httpMethod(values.simpleValue("httpMethod", HttpRequestMethod::valueOf))
         .requestUri(values.get("requestUri"))
         .queryString(values.getOptional("queryString"))
         .relayState(values.transformOptional("relayState", Saml2RelayState::relayState))
         .signatureAlgorithm(values.transformOptional("sigAlg", Saml2SignatureAlgorithm::signatureAlgorithm))
         .signature(values.transformOptional("signature", Saml2Signature::signature))
         .build();
   }

   @SuppressFBWarnings(justification = "generated code")
   Saml2SpInitiatedSloAttributes(
      @NonNull Saml2RequestParameter samlSloRequest,
      @NonNull HttpRequestMethod httpMethod,
      @NonNull String requestUri,
      @NonNull Optional<String> queryString,
      @NonNull Optional<Saml2RelayState> relayState,
      @NonNull Optional<Saml2SignatureAlgorithm> signatureAlgorithm,
      @NonNull Optional<Saml2Signature> signature
   ) {
      if (samlSloRequest == null) {
         throw new NullPointerException("samlSloRequest is marked non-null but is null");
      }

      if (httpMethod == null) {
         throw new NullPointerException("httpMethod is marked non-null but is null");
      }

      if (requestUri == null) {
         throw new NullPointerException("requestUri is marked non-null but is null");
      }

      if (queryString == null) {
         throw new NullPointerException("queryString is marked non-null but is null");
      }

      if (relayState == null) {
         throw new NullPointerException("relayState is marked non-null but is null");
      }

      if (signatureAlgorithm == null) {
         throw new NullPointerException("signatureAlgorithm is marked non-null but is null");
      }

      if (signature == null) {
         throw new NullPointerException("signature is marked non-null but is null");
      }

      this.samlSloRequest = samlSloRequest;
      this.httpMethod = httpMethod;
      this.requestUri = requestUri;
      this.queryString = queryString;
      this.relayState = relayState;
      this.signatureAlgorithm = signatureAlgorithm;
      this.signature = signature;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static Saml2SpInitiatedSloAttributes.Saml2SpInitiatedSloAttributesBuilder builder() {
      return new Saml2SpInitiatedSloAttributes.Saml2SpInitiatedSloAttributesBuilder();
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Saml2RequestParameter getSamlSloRequest() {
      return this.samlSloRequest;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public HttpRequestMethod getHttpMethod() {
      return this.httpMethod;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public String getRequestUri() {
      return this.requestUri;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Optional<String> getQueryString() {
      return this.queryString;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Optional<Saml2RelayState> getRelayState() {
      return this.relayState;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Optional<Saml2SignatureAlgorithm> getSignatureAlgorithm() {
      return this.signatureAlgorithm;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Optional<Saml2Signature> getSignature() {
      return this.signature;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof Saml2SpInitiatedSloAttributes other)) {
         return false;
      } else {
         Object this$samlSloRequest = this.samlSloRequest;
         Object other$samlSloRequest = other.samlSloRequest;
         if (this$samlSloRequest == null ? other$samlSloRequest == null : this$samlSloRequest.equals(other$samlSloRequest)) {
            Object this$httpMethod = this.httpMethod;
            Object other$httpMethod = other.httpMethod;
            if (this$httpMethod == null ? other$httpMethod == null : this$httpMethod.equals(other$httpMethod)) {
               Object this$requestUri = this.requestUri;
               Object other$requestUri = other.requestUri;
               if (this$requestUri == null ? other$requestUri == null : this$requestUri.equals(other$requestUri)) {
                  Object this$queryString = this.queryString;
                  Object other$queryString = other.queryString;
                  if (this$queryString == null ? other$queryString == null : this$queryString.equals(other$queryString)) {
                     Object this$relayState = this.relayState;
                     Object other$relayState = other.relayState;
                     if (this$relayState == null ? other$relayState == null : this$relayState.equals(other$relayState)) {
                        Object this$signatureAlgorithm = this.signatureAlgorithm;
                        Object other$signatureAlgorithm = other.signatureAlgorithm;
                        if (this$signatureAlgorithm == null ? other$signatureAlgorithm == null : this$signatureAlgorithm.equals(other$signatureAlgorithm)) {
                           Object this$signature = this.signature;
                           Object other$signature = other.signature;
                           return this$signature == null ? other$signature == null : this$signature.equals(other$signature);
                        } else {
                           return false;
                        }
                     } else {
                        return false;
                     }
                  } else {
                     return false;
                  }
               } else {
                  return false;
               }
            } else {
               return false;
            }
         } else {
            return false;
         }
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public int hashCode() {
      int PRIME = 59;
      int result = 1;
      Object $samlSloRequest = this.samlSloRequest;
      result = result * 59 + ($samlSloRequest == null ? 43 : $samlSloRequest.hashCode());
      Object $httpMethod = this.httpMethod;
      result = result * 59 + ($httpMethod == null ? 43 : $httpMethod.hashCode());
      Object $requestUri = this.requestUri;
      result = result * 59 + ($requestUri == null ? 43 : $requestUri.hashCode());
      Object $queryString = this.queryString;
      result = result * 59 + ($queryString == null ? 43 : $queryString.hashCode());
      Object $relayState = this.relayState;
      result = result * 59 + ($relayState == null ? 43 : $relayState.hashCode());
      Object $signatureAlgorithm = this.signatureAlgorithm;
      result = result * 59 + ($signatureAlgorithm == null ? 43 : $signatureAlgorithm.hashCode());
      Object $signature = this.signature;
      return result * 59 + ($signature == null ? 43 : $signature.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "Saml2SpInitiatedSloAttributes(samlSloRequest="
         + this.getSamlSloRequest()
         + ", httpMethod="
         + this.getHttpMethod()
         + ", requestUri="
         + this.getRequestUri()
         + ", queryString="
         + this.getQueryString()
         + ", relayState="
         + this.getRelayState()
         + ", signatureAlgorithm="
         + this.getSignatureAlgorithm()
         + ", signature="
         + this.getSignature()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class Saml2SpInitiatedSloAttributesBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Saml2RequestParameter samlSloRequest;
      @SuppressFBWarnings(justification = "generated code")
      private HttpRequestMethod httpMethod;
      @SuppressFBWarnings(justification = "generated code")
      private String requestUri;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<String> queryString;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<Saml2RelayState> relayState;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<Saml2SignatureAlgorithm> signatureAlgorithm;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<Saml2Signature> signature;

      @SuppressFBWarnings(justification = "generated code")
      Saml2SpInitiatedSloAttributesBuilder() {
      }

      @SuppressFBWarnings(justification = "generated code")
      public Saml2SpInitiatedSloAttributes.Saml2SpInitiatedSloAttributesBuilder samlSloRequest(@NonNull Saml2RequestParameter samlSloRequest) {
         if (samlSloRequest == null) {
            throw new NullPointerException("samlSloRequest is marked non-null but is null");
         }

         this.samlSloRequest = samlSloRequest;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Saml2SpInitiatedSloAttributes.Saml2SpInitiatedSloAttributesBuilder httpMethod(@NonNull HttpRequestMethod httpMethod) {
         if (httpMethod == null) {
            throw new NullPointerException("httpMethod is marked non-null but is null");
         }

         this.httpMethod = httpMethod;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Saml2SpInitiatedSloAttributes.Saml2SpInitiatedSloAttributesBuilder requestUri(@NonNull String requestUri) {
         if (requestUri == null) {
            throw new NullPointerException("requestUri is marked non-null but is null");
         }

         this.requestUri = requestUri;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Saml2SpInitiatedSloAttributes.Saml2SpInitiatedSloAttributesBuilder queryString(@NonNull Optional<String> queryString) {
         if (queryString == null) {
            throw new NullPointerException("queryString is marked non-null but is null");
         }

         this.queryString = queryString;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Saml2SpInitiatedSloAttributes.Saml2SpInitiatedSloAttributesBuilder relayState(@NonNull Optional<Saml2RelayState> relayState) {
         if (relayState == null) {
            throw new NullPointerException("relayState is marked non-null but is null");
         }

         this.relayState = relayState;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Saml2SpInitiatedSloAttributes.Saml2SpInitiatedSloAttributesBuilder signatureAlgorithm(
         @NonNull Optional<Saml2SignatureAlgorithm> signatureAlgorithm
      ) {
         if (signatureAlgorithm == null) {
            throw new NullPointerException("signatureAlgorithm is marked non-null but is null");
         }

         this.signatureAlgorithm = signatureAlgorithm;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Saml2SpInitiatedSloAttributes.Saml2SpInitiatedSloAttributesBuilder signature(@NonNull Optional<Saml2Signature> signature) {
         if (signature == null) {
            throw new NullPointerException("signature is marked non-null but is null");
         }

         this.signature = signature;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Saml2SpInitiatedSloAttributes build() {
         return new Saml2SpInitiatedSloAttributes(
            this.samlSloRequest, this.httpMethod, this.requestUri, this.queryString, this.relayState, this.signatureAlgorithm, this.signature
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "Saml2SpInitiatedSloAttributes.Saml2SpInitiatedSloAttributesBuilder(samlSloRequest="
            + this.samlSloRequest
            + ", httpMethod="
            + this.httpMethod
            + ", requestUri="
            + this.requestUri
            + ", queryString="
            + this.queryString
            + ", relayState="
            + this.relayState
            + ", signatureAlgorithm="
            + this.signatureAlgorithm
            + ", signature="
            + this.signature
            + ")";
      }
   }
}
