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

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Optional;
import lombok.NonNull;

public final class Saml2RelayState {
   private final String state;

   private Saml2RelayState(@NonNull String state) {
      if (state == null) {
         throw new NullPointerException("state is marked non-null but is null");
      }

      this.state = state;
   }

   public static Saml2RelayState relayState(String state) {
      return new Saml2RelayState(state);
   }

   public static Saml2RelayState relayState(URI state) {
      return new Saml2RelayState(state.toASCIIString());
   }

   public String value() {
      return this.state;
   }

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

   public Optional<URI> toUri() {
      try {
         return Optional.of(new URI(this.state));
      } catch (URISyntaxException e) {
         return Optional.empty();
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof Saml2RelayState other)) {
         return false;
      } else {
         Object this$state = this.state;
         Object other$state = other.state;
         return this$state == null ? other$state == null : this$state.equals(other$state);
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public int hashCode() {
      int PRIME = 59;
      int result = 1;
      Object $state = this.state;
      return result * 59 + ($state == null ? 43 : $state.hashCode());
   }
}
