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

import com.airlock.iam.airlock2fa.api.domain.model.Airlock2FAAccountId;
import com.airlock.iam.airlock2fa.api.domain.model.Airlock2FADeviceId;
import com.airlock.iam.base.api.domain.model.mapification.MapifiedValues;
import com.airlock.iam.base.domain.model.mapification.MapifiedValuesBuilder;
import com.airlock.iam.flow.api.domain.model.step.StepSession;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;
import lombok.NonNull;

public class Airlock2FARecoveryFlowBindingStepSession implements StepSession {
   private static final String DEVICE_ID_KEY = "deviceId";
   private static final String ACCOUNT_ID_KEY = "accountId";
   private Optional<Airlock2FADeviceId> deviceId = Optional.empty();
   private Optional<Airlock2FAAccountId> accountId = Optional.empty();

   public void setDevice(@NonNull Airlock2FADeviceId deviceId) {
      if (deviceId == null) {
         throw new NullPointerException("deviceId is marked non-null but is null");
      }

      this.deviceId = Optional.of(deviceId);
   }

   public void setAccountId(@NonNull Airlock2FAAccountId accountId) {
      if (accountId == null) {
         throw new NullPointerException("accountId is marked non-null but is null");
      }

      this.accountId = Optional.of(accountId);
   }

   public Airlock2FAAccountId getAccountIdOrThrow() {
      return this.accountId.orElseThrow();
   }

   public Airlock2FADeviceId getDeviceIdOrThrow() {
      return this.deviceId.orElseThrow();
   }

   @Override
   public MapifiedValues mapify() {
      return MapifiedValuesBuilder.mapifiedValues()
         .putIfPresent("deviceId", this.deviceId.map(Airlock2FADeviceId::id))
         .putIfPresent("accountId", this.accountId.map(Airlock2FAAccountId::getId))
         .build();
   }

   public static Airlock2FARecoveryFlowBindingStepSession demapify(MapifiedValues values) {
      return new Airlock2FARecoveryFlowBindingStepSession(
         values.getOptional("deviceId").map(Airlock2FADeviceId::airlock2FADeviceId),
         values.getOptional("accountId").map(Airlock2FAAccountId::airlock2FAAccountId)
      );
   }

   @SuppressFBWarnings(justification = "generated code")
   public Airlock2FARecoveryFlowBindingStepSession(Optional<Airlock2FADeviceId> deviceId, Optional<Airlock2FAAccountId> accountId) {
      this.deviceId = deviceId;
      this.accountId = accountId;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public Optional<Airlock2FADeviceId> getDeviceId() {
      return this.deviceId;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<Airlock2FAAccountId> getAccountId() {
      return this.accountId;
   }

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

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

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