package com.airlock.iam.common.domain.service.state;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public final class StateRepositoryKey {
   private final String id;
   private final StateRepositoryKey.StateEntryType stateEntryType;

   public StateRepositoryKey(String id, StateRepositoryKey.StateEntryType stateEntryType) {
      this.id = id;
      this.stateEntryType = new StateRepositoryKey.ImmutableStateEntryType(stateEntryType.identifier());
   }

   public String value() {
      return this.stateEntryType.identifier() + ":" + this.id;
   }

   public String id() {
      return this.id;
   }

   public StateRepositoryKey.StateEntryType stateEntryType() {
      return this.stateEntryType;
   }

   public boolean hasStateEntryType(StateRepositoryKey.StateEntryType entryType) {
      return this.stateEntryType.identifier().equals(entryType.identifier());
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public String getId() {
      return this.id;
   }

   @SuppressFBWarnings(justification = "generated code")
   public StateRepositoryKey.StateEntryType getStateEntryType() {
      return this.stateEntryType;
   }

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

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

   private record ImmutableStateEntryType(String identifier) implements StateRepositoryKey.StateEntryType {
   }

   public enum StandardStateEntryType implements StateRepositoryKey.StateEntryType {
      SESSION("session"),
      USER("user");

      private final String identifier;

      StandardStateEntryType(String identifier) {
         this.identifier = identifier;
      }

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

   public interface StateEntryType {
      String identifier();
   }
}
