package com.airlock.iam.admin.domain.model.token.airlock2fa;

import com.airlock.iam.airlock2fa.api.domain.model.Airlock2FADeviceId;
import com.airlock.iam.factor.domain.model.airlock2fa.Airlock2FAAppDeviceType;
import com.airlock.iam.factor.domain.model.airlock2fa.Airlock2FAAppDeviceVersion;
import com.airlock.iam.factor.domain.model.airlock2fa.Airlock2FADeviceCapability;
import com.airlock.iam.factor.domain.model.airlock2fa.Airlock2FAFactor;
import com.airlock.iam.factor.domain.model.airlock2fa.Airlock2FAFactorSet;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import lombok.NonNull;

public final class Airlock2FAAdminAppDevice {
   private static final Airlock2FAFactorSet SUPPORTED_FACTORS = Airlock2FAFactorSet.of(
      new Airlock2FAFactor[]{Airlock2FAFactor.ONE_TOUCH, Airlock2FAFactor.OFFLINE_QR_CODE, Airlock2FAFactor.PASSCODE, Airlock2FAFactor.MOBILE_ONLY}
   );
   private final Airlock2FADeviceId deviceId;
   private final Optional<Airlock2FAAppDeviceVersion> appVersion;
   private final Optional<Boolean> appVersionSupported;
   private final String displayName;
   private final Date createdAt;
   private final Date assignedAt;
   @NonNull
   private final List<Airlock2FADeviceCapability> capabilities;
   private final Airlock2FAAppDeviceType type;

   private Airlock2FAAdminAppDevice(
      @NonNull Airlock2FADeviceId deviceId,
      @Nullable Airlock2FAAppDeviceVersion appVersion,
      @Nullable Boolean appVersionSupported,
      @NonNull String displayName,
      @NonNull Date createdAt,
      @NonNull Date assignedAt,
      @NonNull List<Airlock2FADeviceCapability> capabilities,
      @NonNull Airlock2FAAppDeviceType type
   ) {
      if (deviceId == null) {
         throw new NullPointerException("deviceId is marked non-null but is null");
      }

      if (displayName == null) {
         throw new NullPointerException("displayName is marked non-null but is null");
      }

      if (createdAt == null) {
         throw new NullPointerException("createdAt is marked non-null but is null");
      }

      if (assignedAt == null) {
         throw new NullPointerException("assignedAt is marked non-null but is null");
      }

      if (capabilities == null) {
         throw new NullPointerException("capabilities is marked non-null but is null");
      }

      if (type == null) {
         throw new NullPointerException("type is marked non-null but is null");
      }

      this.deviceId = deviceId;
      this.appVersion = Optional.ofNullable(appVersion);
      this.appVersionSupported = Optional.ofNullable(appVersionSupported);
      this.displayName = displayName;
      this.createdAt = createdAt;
      this.assignedAt = assignedAt;
      this.capabilities = capabilities;
      this.type = type;
   }

   public boolean hasId(Airlock2FADeviceId id) {
      return this.deviceId.equals(id);
   }

   public Airlock2FAFactorSet getSupportedFactors() {
      return SUPPORTED_FACTORS.filter(f -> this.capabilities.containsAll(Airlock2FADeviceCapability.requiredCapabilitiesForFactor(f)));
   }

   @SuppressFBWarnings(justification = "generated code")
   public static Airlock2FAAdminAppDevice.Airlock2FAAdminAppDeviceBuilder builder() {
      return new Airlock2FAAdminAppDevice.Airlock2FAAdminAppDeviceBuilder();
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public Optional<Airlock2FAAppDeviceVersion> getAppVersion() {
      return this.appVersion;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<Boolean> getAppVersionSupported() {
      return this.appVersionSupported;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public Date getCreatedAt() {
      return this.createdAt;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Date getAssignedAt() {
      return this.assignedAt;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Airlock2FAAppDeviceType getType() {
      return this.type;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof Airlock2FAAdminAppDevice other)) {
         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$appVersion = this.appVersion;
            Object other$appVersion = other.appVersion;
            if (this$appVersion == null ? other$appVersion == null : this$appVersion.equals(other$appVersion)) {
               Object this$appVersionSupported = this.appVersionSupported;
               Object other$appVersionSupported = other.appVersionSupported;
               if (this$appVersionSupported == null ? other$appVersionSupported == null : this$appVersionSupported.equals(other$appVersionSupported)) {
                  Object this$displayName = this.displayName;
                  Object other$displayName = other.displayName;
                  if (this$displayName == null ? other$displayName == null : this$displayName.equals(other$displayName)) {
                     Object this$createdAt = this.createdAt;
                     Object other$createdAt = other.createdAt;
                     if (this$createdAt == null ? other$createdAt == null : this$createdAt.equals(other$createdAt)) {
                        Object this$assignedAt = this.assignedAt;
                        Object other$assignedAt = other.assignedAt;
                        if (this$assignedAt == null ? other$assignedAt == null : this$assignedAt.equals(other$assignedAt)) {
                           Object this$capabilities = this.capabilities;
                           Object other$capabilities = other.capabilities;
                           if (this$capabilities == null ? other$capabilities == null : this$capabilities.equals(other$capabilities)) {
                              Object this$type = this.type;
                              Object other$type = other.type;
                              return this$type == null ? other$type == null : this$type.equals(other$type);
                           } else {
                              return false;
                           }
                        } else {
                           return false;
                        }
                     } else {
                        return false;
                     }
                  } else {
                     return false;
                  }
               } else {
                  return false;
               }
            } else {
               return false;
            }
         } else {
            return false;
         }
      }
   }

   @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 $appVersion = this.appVersion;
      result = result * 59 + ($appVersion == null ? 43 : $appVersion.hashCode());
      Object $appVersionSupported = this.appVersionSupported;
      result = result * 59 + ($appVersionSupported == null ? 43 : $appVersionSupported.hashCode());
      Object $displayName = this.displayName;
      result = result * 59 + ($displayName == null ? 43 : $displayName.hashCode());
      Object $createdAt = this.createdAt;
      result = result * 59 + ($createdAt == null ? 43 : $createdAt.hashCode());
      Object $assignedAt = this.assignedAt;
      result = result * 59 + ($assignedAt == null ? 43 : $assignedAt.hashCode());
      Object $capabilities = this.capabilities;
      result = result * 59 + ($capabilities == null ? 43 : $capabilities.hashCode());
      Object $type = this.type;
      return result * 59 + ($type == null ? 43 : $type.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "Airlock2FAAdminAppDevice(deviceId="
         + this.getDeviceId()
         + ", appVersion="
         + this.getAppVersion()
         + ", appVersionSupported="
         + this.getAppVersionSupported()
         + ", displayName="
         + this.getDisplayName()
         + ", createdAt="
         + this.getCreatedAt()
         + ", assignedAt="
         + this.getAssignedAt()
         + ", capabilities="
         + this.capabilities
         + ", type="
         + this.getType()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class Airlock2FAAdminAppDeviceBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Airlock2FADeviceId deviceId;
      @SuppressFBWarnings(justification = "generated code")
      private Airlock2FAAppDeviceVersion appVersion;
      @SuppressFBWarnings(justification = "generated code")
      private Boolean appVersionSupported;
      @SuppressFBWarnings(justification = "generated code")
      private String displayName;
      @SuppressFBWarnings(justification = "generated code")
      private Date createdAt;
      @SuppressFBWarnings(justification = "generated code")
      private Date assignedAt;
      @SuppressFBWarnings(justification = "generated code")
      private List<Airlock2FADeviceCapability> capabilities;
      @SuppressFBWarnings(justification = "generated code")
      private Airlock2FAAppDeviceType type;

      @SuppressFBWarnings(justification = "generated code")
      Airlock2FAAdminAppDeviceBuilder() {
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAAdminAppDevice.Airlock2FAAdminAppDeviceBuilder deviceId(@NonNull Airlock2FADeviceId deviceId) {
         if (deviceId == null) {
            throw new NullPointerException("deviceId is marked non-null but is null");
         }

         this.deviceId = deviceId;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAAdminAppDevice.Airlock2FAAdminAppDeviceBuilder appVersion(@Nullable Airlock2FAAppDeviceVersion appVersion) {
         this.appVersion = appVersion;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAAdminAppDevice.Airlock2FAAdminAppDeviceBuilder appVersionSupported(@Nullable Boolean appVersionSupported) {
         this.appVersionSupported = appVersionSupported;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAAdminAppDevice.Airlock2FAAdminAppDeviceBuilder displayName(@NonNull String displayName) {
         if (displayName == null) {
            throw new NullPointerException("displayName is marked non-null but is null");
         }

         this.displayName = displayName;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAAdminAppDevice.Airlock2FAAdminAppDeviceBuilder createdAt(@NonNull Date createdAt) {
         if (createdAt == null) {
            throw new NullPointerException("createdAt is marked non-null but is null");
         }

         this.createdAt = createdAt;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAAdminAppDevice.Airlock2FAAdminAppDeviceBuilder assignedAt(@NonNull Date assignedAt) {
         if (assignedAt == null) {
            throw new NullPointerException("assignedAt is marked non-null but is null");
         }

         this.assignedAt = assignedAt;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAAdminAppDevice.Airlock2FAAdminAppDeviceBuilder capabilities(@NonNull List<Airlock2FADeviceCapability> capabilities) {
         if (capabilities == null) {
            throw new NullPointerException("capabilities is marked non-null but is null");
         }

         this.capabilities = capabilities;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAAdminAppDevice.Airlock2FAAdminAppDeviceBuilder type(@NonNull Airlock2FAAppDeviceType type) {
         if (type == null) {
            throw new NullPointerException("type is marked non-null but is null");
         }

         this.type = type;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAAdminAppDevice build() {
         return new Airlock2FAAdminAppDevice(
            this.deviceId, this.appVersion, this.appVersionSupported, this.displayName, this.createdAt, this.assignedAt, this.capabilities, this.type
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "Airlock2FAAdminAppDevice.Airlock2FAAdminAppDeviceBuilder(deviceId="
            + this.deviceId
            + ", appVersion="
            + this.appVersion
            + ", appVersionSupported="
            + this.appVersionSupported
            + ", displayName="
            + this.displayName
            + ", createdAt="
            + this.createdAt
            + ", assignedAt="
            + this.assignedAt
            + ", capabilities="
            + this.capabilities
            + ", type="
            + this.type
            + ")";
      }
   }
}
