package com.airlock.iam.flow.shared.domain.model.attributes;

import com.airlock.iam.base.api.domain.model.mapification.MapifiedValues;
import com.airlock.iam.base.domain.model.mapification.MapifiedValuesBuilder;
import com.airlock.iam.elog.api.ELogger;
import com.airlock.iam.elog.api.ELoggerFactory;
import com.airlock.iam.flow.api.domain.model.session.SingleFlowScopedFlowAttribute;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public final class AuthTokenIdAttribute implements SingleFlowScopedFlowAttribute<AuthTokenIdAttribute> {
   private static final String AUTH_TOKEN_ID_KEY = "id";
   private static final ELogger LOG = ELoggerFactory.getLogger(AuthTokenIdAttribute.class);
   private final String authTokenId;

   public static AuthTokenIdAttribute authTokenIdAttribute(String rawAuthTokenId) {
      return new AuthTokenIdAttribute(rawAuthTokenId);
   }

   private AuthTokenIdAttribute(String rawAuthTokenId) {
      this.authTokenId = rawAuthTokenId;
   }

   public AuthTokenIdAttribute mergeWith(AuthTokenIdAttribute newAuthTokenId) {
      LOG.debug("Replacing authTokenId");
      return newAuthTokenId;
   }

   @Override
   public MapifiedValues mapify() {
      return MapifiedValuesBuilder.mapifiedValues().put("id", this.authTokenId).build();
   }

   public static AuthTokenIdAttribute demapify(MapifiedValues values) {
      return authTokenIdAttribute(values.get("id"));
   }

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

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

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "AuthTokenIdAttribute(authTokenId=" + this.getAuthTokenId() + ")";
   }
}
