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

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import java.util.Optional;
import java.util.OptionalInt;
import lombok.NonNull;
import org.apache.commons.lang3.StringUtils;

public final class RememberMeCookie {
   private final String name;
   private final Optional<String> domain;
   private final Optional<String> path;
   private final String value;
   private final OptionalInt maxAge;

   private RememberMeCookie(@NonNull String name, @Nullable String domain, @Nullable String path, @NonNull String value, @Nullable Integer maxAge) {
      if (name == null) {
         throw new NullPointerException("name is marked non-null but is null");
      }

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

      this.name = name;
      this.domain = Optional.ofNullable(domain).filter(StringUtils::isNotBlank);
      this.path = Optional.ofNullable(path).filter(StringUtils::isNotBlank);
      this.value = value;
      this.maxAge = maxAge == null ? OptionalInt.empty() : OptionalInt.of(maxAge);
   }

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

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

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

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

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

   @SuppressFBWarnings(justification = "generated code")
   public OptionalInt getMaxAge() {
      return this.maxAge;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof RememberMeCookie other)) {
         return false;
      } else {
         Object this$name = this.name;
         Object other$name = other.name;
         if (this$name == null ? other$name == null : this$name.equals(other$name)) {
            Object this$domain = this.domain;
            Object other$domain = other.domain;
            if (this$domain == null ? other$domain == null : this$domain.equals(other$domain)) {
               Object this$path = this.path;
               Object other$path = other.path;
               if (this$path == null ? other$path == null : this$path.equals(other$path)) {
                  Object this$value = this.value;
                  Object other$value = other.value;
                  if (this$value == null ? other$value == null : this$value.equals(other$value)) {
                     Object this$maxAge = this.maxAge;
                     Object other$maxAge = other.maxAge;
                     return this$maxAge == null ? other$maxAge == null : this$maxAge.equals(other$maxAge);
                  } 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 $name = this.name;
      result = result * 59 + ($name == null ? 43 : $name.hashCode());
      Object $domain = this.domain;
      result = result * 59 + ($domain == null ? 43 : $domain.hashCode());
      Object $path = this.path;
      result = result * 59 + ($path == null ? 43 : $path.hashCode());
      Object $value = this.value;
      result = result * 59 + ($value == null ? 43 : $value.hashCode());
      Object $maxAge = this.maxAge;
      return result * 59 + ($maxAge == null ? 43 : $maxAge.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "RememberMeCookie(name="
         + this.getName()
         + ", domain="
         + this.getDomain()
         + ", path="
         + this.getPath()
         + ", value="
         + this.getValue()
         + ", maxAge="
         + this.getMaxAge()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class RememberMeCookieBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String name;
      @SuppressFBWarnings(justification = "generated code")
      private String domain;
      @SuppressFBWarnings(justification = "generated code")
      private String path;
      @SuppressFBWarnings(justification = "generated code")
      private String value;
      @SuppressFBWarnings(justification = "generated code")
      private Integer maxAge;

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

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

         this.name = name;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RememberMeCookie.RememberMeCookieBuilder domain(@Nullable String domain) {
         this.domain = domain;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RememberMeCookie.RememberMeCookieBuilder path(@Nullable String path) {
         this.path = path;
         return this;
      }

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

         this.value = value;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RememberMeCookie.RememberMeCookieBuilder maxAge(@Nullable Integer maxAge) {
         this.maxAge = maxAge;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public RememberMeCookie build() {
         return new RememberMeCookie(this.name, this.domain, this.path, this.value, this.maxAge);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "RememberMeCookie.RememberMeCookieBuilder(name="
            + this.name
            + ", domain="
            + this.domain
            + ", path="
            + this.path
            + ", value="
            + this.value
            + ", maxAge="
            + this.maxAge
            + ")";
      }
   }
}
