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

import com.airlock.iam.base.api.domain.model.mapification.MapifiedValues;
import com.airlock.iam.base.domain.model.mapification.MapifiedValuesBuilder;
import com.airlock.iam.common.api.domain.model.authmethod.AuthenticationMethod;
import com.airlock.iam.core.misc.impl.authen.AuthenticationMethodFactory;
import com.airlock.iam.flow.api.domain.model.session.SingleFlowScopedFlowAttribute;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

public final class CurrentFailedAuthenticationMethod implements SingleFlowScopedFlowAttribute<CurrentFailedAuthenticationMethod> {
   private static final String ID_KEY = "id";
   private final AuthenticationMethod failedAuthMethod;

   public CurrentFailedAuthenticationMethod mergeWith(CurrentFailedAuthenticationMethod newAttribute) {
      return newAttribute;
   }

   public static CurrentFailedAuthenticationMethod currentFailedAuthMethodOf(AuthenticationMethod authMethod) {
      return new CurrentFailedAuthenticationMethod(authMethod);
   }

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

   public static CurrentFailedAuthenticationMethod demapify(MapifiedValues values) {
      return new CurrentFailedAuthenticationMethod(AuthenticationMethodFactory.authMethodFor(values.get("id")));
   }

   @SuppressFBWarnings(justification = "generated code")
   public AuthenticationMethod getFailedAuthMethod() {
      return this.failedAuthMethod;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "CurrentFailedAuthenticationMethod(failedAuthMethod=" + this.getFailedAuthMethod() + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   private CurrentFailedAuthenticationMethod(AuthenticationMethod failedAuthMethod) {
      this.failedAuthMethod = failedAuthMethod;
   }
}
