package com.airlock.iam.common.domain.model.identity;

import com.airlock.iam.base.api.domain.model.Entity;
import com.airlock.iam.base.api.domain.model.identity.Identity;
import com.airlock.iam.common.domain.model.AbstractDefaultIdentity;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.NonNull;

public final class DefaultStringIdentity<E extends Entity<E>> extends AbstractDefaultIdentity<E> {
   @NonNull
   private final String internalId;
   @NonNull
   private final Class<E> type;

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

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

   public static <T extends Entity<T>> Identity<T> identity(String id, Class<T> type) {
      return new DefaultStringIdentity<>(id, type);
   }

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Class<E> getType() {
      return this.type;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   protected boolean canEqual(Object other) {
      return other instanceof DefaultStringIdentity;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   private DefaultStringIdentity(@NonNull String internalId, @NonNull Class<E> type) {
      if (internalId == null) {
         throw new NullPointerException("internalId is marked non-null but is null");
      }

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

      this.internalId = internalId;
      this.type = type;
   }
}
