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

import com.airlock.iam.base.api.domain.model.Entity;
import com.airlock.iam.base.api.domain.model.user.UserId;
import com.airlock.iam.factor.domain.model.airlock2fa.Airlock2FAHardwareTokenActivationCode;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import java.util.Optional;
import lombok.NonNull;

public final class Airlock2FAShipmentLetter implements Entity<Airlock2FAShipmentLetter> {
   @NonNull
   private final Airlock2FAShipmentLetterId id;
   @NonNull
   private final UserId deviceOwner;
   @NonNull
   private final String deviceSerialNumber;
   @NonNull
   private final Optional<Airlock2FAHardwareTokenActivationCode> deviceActivationCode;
   @NonNull
   private final String deviceManufacturer;
   @NonNull
   private final String deviceModel;

   private Airlock2FAShipmentLetter(
      @Nullable String id,
      @NonNull UserId deviceOwner,
      @NonNull String deviceSerialNumber,
      @NonNull Optional<Airlock2FAHardwareTokenActivationCode> deviceActivationCode,
      @NonNull String deviceManufacturer,
      @NonNull String deviceModel
   ) {
      if (deviceOwner == null) {
         throw new NullPointerException("deviceOwner is marked non-null but is null");
      }

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

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

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

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

      this.id = Optional.ofNullable(id)
         .map(Airlock2FAShipmentLetterId::airlock2FAShipmentLetterId)
         .orElseGet(Airlock2FAShipmentLetterId::generateAirlock2FAActivationLetterId);
      this.deviceOwner = deviceOwner;
      this.deviceSerialNumber = deviceSerialNumber;
      this.deviceActivationCode = deviceActivationCode;
      this.deviceManufacturer = deviceManufacturer;
      this.deviceModel = deviceModel;
   }

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Airlock2FAShipmentLetterId getId() {
      return this.id;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public UserId getDeviceOwner() {
      return this.deviceOwner;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public String getDeviceSerialNumber() {
      return this.deviceSerialNumber;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Optional<Airlock2FAHardwareTokenActivationCode> getDeviceActivationCode() {
      return this.deviceActivationCode;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public String getDeviceManufacturer() {
      return this.deviceManufacturer;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public String getDeviceModel() {
      return this.deviceModel;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "Airlock2FAShipmentLetter(id="
         + this.getId()
         + ", deviceOwner="
         + this.getDeviceOwner()
         + ", deviceSerialNumber="
         + this.getDeviceSerialNumber()
         + ", deviceActivationCode="
         + this.getDeviceActivationCode()
         + ", deviceManufacturer="
         + this.getDeviceManufacturer()
         + ", deviceModel="
         + this.getDeviceModel()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   private Airlock2FAShipmentLetter(
      @NonNull Airlock2FAShipmentLetterId id,
      @NonNull UserId deviceOwner,
      @NonNull String deviceSerialNumber,
      @NonNull Optional<Airlock2FAHardwareTokenActivationCode> deviceActivationCode,
      @NonNull String deviceManufacturer,
      @NonNull String deviceModel
   ) {
      if (id == null) {
         throw new NullPointerException("id is marked non-null but is null");
      }

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

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

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

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

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

      this.id = id;
      this.deviceOwner = deviceOwner;
      this.deviceSerialNumber = deviceSerialNumber;
      this.deviceActivationCode = deviceActivationCode;
      this.deviceManufacturer = deviceManufacturer;
      this.deviceModel = deviceModel;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public static class Airlock2FAShipmentLetterBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String id;
      @SuppressFBWarnings(justification = "generated code")
      private UserId deviceOwner;
      @SuppressFBWarnings(justification = "generated code")
      private String deviceSerialNumber;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<Airlock2FAHardwareTokenActivationCode> deviceActivationCode;
      @SuppressFBWarnings(justification = "generated code")
      private String deviceManufacturer;
      @SuppressFBWarnings(justification = "generated code")
      private String deviceModel;

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

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAShipmentLetter.Airlock2FAShipmentLetterBuilder id(@Nullable String id) {
         this.id = id;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAShipmentLetter.Airlock2FAShipmentLetterBuilder deviceOwner(@NonNull UserId deviceOwner) {
         if (deviceOwner == null) {
            throw new NullPointerException("deviceOwner is marked non-null but is null");
         }

         this.deviceOwner = deviceOwner;
         return this;
      }

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

         this.deviceSerialNumber = deviceSerialNumber;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAShipmentLetter.Airlock2FAShipmentLetterBuilder deviceActivationCode(
         @NonNull Optional<Airlock2FAHardwareTokenActivationCode> deviceActivationCode
      ) {
         if (deviceActivationCode == null) {
            throw new NullPointerException("deviceActivationCode is marked non-null but is null");
         }

         this.deviceActivationCode = deviceActivationCode;
         return this;
      }

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

         this.deviceManufacturer = deviceManufacturer;
         return this;
      }

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

         this.deviceModel = deviceModel;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Airlock2FAShipmentLetter build() {
         return new Airlock2FAShipmentLetter(
            this.id, this.deviceOwner, this.deviceSerialNumber, this.deviceActivationCode, this.deviceManufacturer, this.deviceModel
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "Airlock2FAShipmentLetter.Airlock2FAShipmentLetterBuilder(id="
            + this.id
            + ", deviceOwner="
            + this.deviceOwner
            + ", deviceSerialNumber="
            + this.deviceSerialNumber
            + ", deviceActivationCode="
            + this.deviceActivationCode
            + ", deviceManufacturer="
            + this.deviceManufacturer
            + ", deviceModel="
            + this.deviceModel
            + ")";
      }
   }
}
