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

import com.airlock.iam.base.api.domain.model.mapification.MapifiedValues;
import com.airlock.iam.base.domain.model.mapification.MapifiedValuesBuilder;
import com.airlock.iam.core.misc.impl.tokenverifier.oathotp.OtpCredBeanData;
import com.airlock.iam.flow.api.domain.model.step.StepSession;
import com.airlock.iam.flow.shared.api.domain.model.session.ChangeDescriptionFlowAttribute;
import com.airlock.iam.flow.shared.api.domain.model.session.UserSessionScopedFlowAttribute;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;

public class OathOtpActivationStepSession
   implements StepSession,
   UserSessionScopedFlowAttribute<OathOtpActivationStepSession>,
   ChangeDescriptionFlowAttribute<OathOtpActivationStepSession> {
   private Optional<OtpCredBeanData> credBean = Optional.empty();

   public static OathOtpActivationStepSession oathOtpActivationStepSession(OtpCredBeanData credBean) {
      return new OathOtpActivationStepSession(Optional.of(credBean));
   }

   public void setCredBean(OtpCredBeanData credBean) {
      this.credBean = Optional.ofNullable(credBean);
   }

   @Override
   public MapifiedValues mapify() {
      return MapifiedValuesBuilder.mapifiedValues().putIfPresent("credData", this.credBean.map(OtpCredBeanData::serialize)).build();
   }

   public static OathOtpActivationStepSession demapify(MapifiedValues values) {
      return new OathOtpActivationStepSession(values.transformOptional("credData", OtpCredBeanData::deserialize));
   }

   public OathOtpActivationStepSession copyAttribute() {
      return demapify(this.mapify());
   }

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

   @Override
   public String description() {
      return "OATH OTP Activation";
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<OtpCredBeanData> getCredBean() {
      return this.credBean;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof OathOtpActivationStepSession other)) {
         return false;
      } else {
         if (!other.canEqual(this)) {
            return false;
         }

         Object this$credBean = this.credBean;
         Object other$credBean = other.credBean;
         return this$credBean == null ? other$credBean == null : this$credBean.equals(other$credBean);
      }
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public OathOtpActivationStepSession() {
   }

   @SuppressFBWarnings(justification = "generated code")
   private OathOtpActivationStepSession(Optional<OtpCredBeanData> credBean) {
      this.credBean = credBean;
   }
}
