package com.airlock.iam.authentication.domain.model.migration;

import com.airlock.iam.base.api.domain.model.mapification.Mapifiable;
import com.airlock.iam.base.api.domain.model.mapification.MapifiedValues;
import com.airlock.iam.base.domain.model.mapification.MapificationUtils;
import com.airlock.iam.base.domain.model.mapification.MapifiedValuesBuilder;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import java.util.Date;
import java.util.Optional;

public final class MigrationInfo implements Mapifiable {
   private static final String NOT_AFTER_KEY = "notAfter";
   private static final String REJECTABLE_KEY = "rejectable";
   private static final String SKIPPABLE_KEY = "skippable";
   @Nullable
   private final Date notAfter;
   private final boolean rejectPossible;
   private final boolean skipPossible;

   @Override
   public MapifiedValues mapify() {
      return MapifiedValuesBuilder.mapifiedValues()
         .putIfPresent("notAfter", Optional.ofNullable(this.notAfter).map(MapificationUtils::mapifyDate))
         .put("rejectable", this.rejectPossible)
         .put("skippable", this.skipPossible)
         .build();
   }

   public static MigrationInfo demapify(MapifiedValues values) {
      return new MigrationInfo(
         values.demapifyOptional("notAfter", MapificationUtils::demapifyDate).orElse(null), values.<Boolean>get("rejectable"), values.<Boolean>get("skippable")
      );
   }

   @SuppressFBWarnings(justification = "generated code")
   public MigrationInfo(@Nullable Date notAfter, boolean rejectPossible, boolean skipPossible) {
      this.notAfter = notAfter;
      this.rejectPossible = rejectPossible;
      this.skipPossible = skipPossible;
   }

   @Nullable
   @SuppressFBWarnings(justification = "generated code")
   public Date getNotAfter() {
      return this.notAfter;
   }

   @SuppressFBWarnings(justification = "generated code")
   public boolean isRejectPossible() {
      return this.rejectPossible;
   }

   @SuppressFBWarnings(justification = "generated code")
   public boolean isSkipPossible() {
      return this.skipPossible;
   }

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

         if (this.skipPossible != other.skipPossible) {
            return false;
         }

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

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "MigrationInfo(notAfter=" + this.getNotAfter() + ", rejectPossible=" + this.isRejectPossible() + ", skipPossible=" + this.isSkipPossible() + ")";
   }
}
