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

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.StepResultData;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;

public final class CrontoActivationChallenge implements StepResultData {
   private static final String CHALLENGE_IMAGE_KEY = "challengeImage";
   private static final String SECURE_CHANNEL_CHALLENGE_KEY = "secureChannelChallenge";
   private final String challengeImage;
   private final Optional<String> secureChannelChallenge;

   public static CrontoActivationChallenge of(CrontoDeviceActivationChallenge challenge) {
      return new CrontoActivationChallenge(challenge.getChallengeImage().base64image(), challenge.getSecureChannelChallenge());
   }

   @Override
   public MapifiedValues mapify() {
      return MapifiedValuesBuilder.mapifiedValues()
         .put("challengeImage", this.challengeImage)
         .putIfPresent("secureChannelChallenge", this.secureChannelChallenge)
         .build();
   }

   public static CrontoActivationChallenge demapify(MapifiedValues values) {
      return new CrontoActivationChallenge(values.get("challengeImage"), values.getOptional("secureChannelChallenge"));
   }

   @SuppressFBWarnings(justification = "generated code")
   public CrontoActivationChallenge(String challengeImage, Optional<String> secureChannelChallenge) {
      this.challengeImage = challengeImage;
      this.secureChannelChallenge = secureChannelChallenge;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public Optional<String> getSecureChannelChallenge() {
      return this.secureChannelChallenge;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "CrontoActivationChallenge(challengeImage=" + this.getChallengeImage() + ", secureChannelChallenge=" + this.getSecureChannelChallenge() + ")";
   }
}
