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

import com.airlock.iam.common.api.domain.model.geolocation.Geolocation;
import com.airlock.iam.common.api.domain.model.request.IpAddress;
import com.airlock.iam.common.domain.model.request.UserAgentRequestHeader;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import java.util.Optional;
import lombok.NonNull;

public final class RememberMeRequestMetadata {
   @NonNull
   private final IpAddress requestIpAddress;
   @NonNull
   private final Optional<UserAgentRequestHeader> userAgentHeader;
   @NonNull
   private final Optional<Geolocation> geolocation;

   private RememberMeRequestMetadata(@NonNull IpAddress requestIpAddress, @Nullable UserAgentRequestHeader userAgentHeader, @Nullable Geolocation geolocation) {
      if (requestIpAddress == null) {
         throw new NullPointerException("requestIpAddress is marked non-null but is null");
      }

      this.requestIpAddress = requestIpAddress;
      this.userAgentHeader = Optional.ofNullable(userAgentHeader);
      this.geolocation = Optional.ofNullable(geolocation);
   }

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public IpAddress requestIpAddress() {
      return this.requestIpAddress;
   }

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

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

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

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "RememberMeRequestMetadata(requestIpAddress="
         + this.requestIpAddress()
         + ", userAgentHeader="
         + this.userAgentHeader()
         + ", geolocation="
         + this.geolocation()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class RememberMeRequestMetadataBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private IpAddress requestIpAddress;
      @SuppressFBWarnings(justification = "generated code")
      private UserAgentRequestHeader userAgentHeader;
      @SuppressFBWarnings(justification = "generated code")
      private Geolocation geolocation;

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

      @SuppressFBWarnings(justification = "generated code")
      public RememberMeRequestMetadata.RememberMeRequestMetadataBuilder requestIpAddress(@NonNull IpAddress requestIpAddress) {
         if (requestIpAddress == null) {
            throw new NullPointerException("requestIpAddress is marked non-null but is null");
         }

         this.requestIpAddress = requestIpAddress;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RememberMeRequestMetadata.RememberMeRequestMetadataBuilder userAgentHeader(@Nullable UserAgentRequestHeader userAgentHeader) {
         this.userAgentHeader = userAgentHeader;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RememberMeRequestMetadata.RememberMeRequestMetadataBuilder geolocation(@Nullable Geolocation geolocation) {
         this.geolocation = geolocation;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RememberMeRequestMetadata build() {
         return new RememberMeRequestMetadata(this.requestIpAddress, this.userAgentHeader, this.geolocation);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "RememberMeRequestMetadata.RememberMeRequestMetadataBuilder(requestIpAddress="
            + this.requestIpAddress
            + ", userAgentHeader="
            + this.userAgentHeader
            + ", geolocation="
            + this.geolocation
            + ")";
      }
   }
}
