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

import com.airlock.iam.security.util.crypto.random.AlphanumericRandomStringGenerator;
import com.google.common.base.Preconditions;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Objects;

public final class State {
   private static final int RANDOM_CHARS = 30;
   private final String state;

   public static State random() {
      return new State();
   }

   public static State state(String state) {
      Preconditions.checkArgument(state != null, "Invalid state: null");
      return new State(state);
   }

   private State() {
      this.state = AlphanumericRandomStringGenerator.generateAlphanumericRandomString(30);
   }

   private State(String state) {
      this.state = state;
   }

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

   public boolean isValid(State other) {
      return Objects.equals(this.state, other.state);
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof State 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());
   }

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