package com.airlock.iam.admin.domain.model.maintenancemessage;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Map.Entry;

@SuppressFBWarnings("UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR")
public final class MaintenanceMessage {
   private String name;
   private Optional<String> location;
   private boolean active;
   private boolean systemAvailable;
   private Date validFrom;
   private Date validTo;
   private Map<String, String> translations;

   public MaintenanceMessage() {
      this.location = Optional.empty();
      this.translations = new HashMap<>();
   }

   public boolean isValidNow() {
      Date now = new Date();
      boolean fromOk = true;
      boolean toOk = true;
      if (this.validFrom != null) {
         fromOk = !now.before(this.validFrom);
      }

      if (this.validTo != null) {
         toOk = !now.after(this.validTo);
      }

      return fromOk && toOk;
   }

   public boolean isValidInFuture() {
      Date now = new Date();
      return now.before(this.validFrom);
   }

   public static MaintenanceMessage.MaintenanceMessageBuilder builder() {
      return new MaintenanceMessage().toBuilder();
   }

   @SuppressFBWarnings(justification = "generated code")
   public MaintenanceMessage.MaintenanceMessageBuilder toBuilder() {
      MaintenanceMessage.MaintenanceMessageBuilder builder = new MaintenanceMessage.MaintenanceMessageBuilder()
         .name(this.name)
         .location(this.location)
         .active(this.active)
         .systemAvailable(this.systemAvailable)
         .validFrom(this.validFrom)
         .validTo(this.validTo);
      if (this.translations != null) {
         builder.translations(this.translations);
      }

      return builder;
   }

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

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

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

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

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

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

   @SuppressFBWarnings(justification = "generated code")
   public Map<String, String> getTranslations() {
      return this.translations;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public void setLocation(Optional<String> location) {
      this.location = location;
   }

   @SuppressFBWarnings(justification = "generated code")
   public void setActive(boolean active) {
      this.active = active;
   }

   @SuppressFBWarnings(justification = "generated code")
   public void setSystemAvailable(boolean systemAvailable) {
      this.systemAvailable = systemAvailable;
   }

   @SuppressFBWarnings(justification = "generated code")
   public void setValidFrom(Date validFrom) {
      this.validFrom = validFrom;
   }

   @SuppressFBWarnings(justification = "generated code")
   public void setValidTo(Date validTo) {
      this.validTo = validTo;
   }

   @SuppressFBWarnings(justification = "generated code")
   public void setTranslations(Map<String, String> translations) {
      this.translations = translations;
   }

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

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

         Object this$name = this.name;
         Object other$name = other.name;
         if (this$name == null ? other$name == null : this$name.equals(other$name)) {
            Object this$location = this.location;
            Object other$location = other.location;
            if (this$location == null ? other$location == null : this$location.equals(other$location)) {
               Object this$validFrom = this.validFrom;
               Object other$validFrom = other.validFrom;
               if (this$validFrom == null ? other$validFrom == null : this$validFrom.equals(other$validFrom)) {
                  Object this$validTo = this.validTo;
                  Object other$validTo = other.validTo;
                  if (this$validTo == null ? other$validTo == null : this$validTo.equals(other$validTo)) {
                     Object this$translations = this.translations;
                     Object other$translations = other.translations;
                     return this$translations == null ? other$translations == null : this$translations.equals(other$translations);
                  } 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;
      result = result * 59 + (this.active ? 79 : 97);
      result = result * 59 + (this.systemAvailable ? 79 : 97);
      Object $name = this.name;
      result = result * 59 + ($name == null ? 43 : $name.hashCode());
      Object $location = this.location;
      result = result * 59 + ($location == null ? 43 : $location.hashCode());
      Object $validFrom = this.validFrom;
      result = result * 59 + ($validFrom == null ? 43 : $validFrom.hashCode());
      Object $validTo = this.validTo;
      result = result * 59 + ($validTo == null ? 43 : $validTo.hashCode());
      Object $translations = this.translations;
      return result * 59 + ($translations == null ? 43 : $translations.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "MaintenanceMessage(name="
         + this.getName()
         + ", location="
         + this.getLocation()
         + ", active="
         + this.isActive()
         + ", systemAvailable="
         + this.isSystemAvailable()
         + ", validFrom="
         + this.getValidFrom()
         + ", validTo="
         + this.getValidTo()
         + ", translations="
         + this.getTranslations()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public MaintenanceMessage(
      String name, Optional<String> location, boolean active, boolean systemAvailable, Date validFrom, Date validTo, Map<String, String> translations
   ) {
      this.name = name;
      this.location = location;
      this.active = active;
      this.systemAvailable = systemAvailable;
      this.validFrom = validFrom;
      this.validTo = validTo;
      this.translations = translations;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class MaintenanceMessageBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String name;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<String> location;
      @SuppressFBWarnings(justification = "generated code")
      private boolean active;
      @SuppressFBWarnings(justification = "generated code")
      private boolean systemAvailable;
      @SuppressFBWarnings(justification = "generated code")
      private Date validFrom;
      @SuppressFBWarnings(justification = "generated code")
      private Date validTo;
      @SuppressFBWarnings(justification = "generated code")
      private ArrayList<String> translations$key;
      @SuppressFBWarnings(justification = "generated code")
      private ArrayList<String> translations$value;

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

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

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

      @SuppressFBWarnings(justification = "generated code")
      public MaintenanceMessage.MaintenanceMessageBuilder active(boolean active) {
         this.active = active;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public MaintenanceMessage.MaintenanceMessageBuilder systemAvailable(boolean systemAvailable) {
         this.systemAvailable = systemAvailable;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public MaintenanceMessage.MaintenanceMessageBuilder validFrom(Date validFrom) {
         this.validFrom = validFrom;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public MaintenanceMessage.MaintenanceMessageBuilder validTo(Date validTo) {
         this.validTo = validTo;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public MaintenanceMessage.MaintenanceMessageBuilder translation(String translationKey, String translationValue) {
         if (this.translations$key == null) {
            this.translations$key = new ArrayList<>();
            this.translations$value = new ArrayList<>();
         }

         this.translations$key.add(translationKey);
         this.translations$value.add(translationValue);
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public MaintenanceMessage.MaintenanceMessageBuilder translations(Map<? extends String, ? extends String> translations) {
         if (translations == null) {
            throw new NullPointerException("translations cannot be null");
         }

         if (this.translations$key == null) {
            this.translations$key = new ArrayList<>();
            this.translations$value = new ArrayList<>();
         }

         for (Entry<? extends String, ? extends String> $lombokEntry : translations.entrySet()) {
            this.translations$key.add($lombokEntry.getKey());
            this.translations$value.add($lombokEntry.getValue());
         }

         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public MaintenanceMessage.MaintenanceMessageBuilder clearTranslations() {
         if (this.translations$key != null) {
            this.translations$key.clear();
            this.translations$value.clear();
         }

         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public MaintenanceMessage build() {
         return new MaintenanceMessage(
            this.name,
            this.location,
            this.active,
            this.systemAvailable,
            this.validFrom,
            this.validTo,
            switch (this.translations$key == null ? 0 : this.translations$key.size()) {
               case 0 -> Collections.emptyMap();
               case 1 -> Collections.singletonMap(this.translations$key.get(0), this.translations$value.get(0));
               default -> {
                  Map<String, String> translations = new LinkedHashMap<>(
                     this.translations$key.size() < 1073741824 ? 1 + this.translations$key.size() + (this.translations$key.size() - 3) / 3 : Integer.MAX_VALUE
                  );

                  for (int $i = 0; $i < this.translations$key.size(); $i++) {
                     translations.put(this.translations$key.get($i), this.translations$value.get($i));
                  }

                  yield Collections.unmodifiableMap(translations);
               }
            }
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "MaintenanceMessage.MaintenanceMessageBuilder(name="
            + this.name
            + ", location="
            + this.location
            + ", active="
            + this.active
            + ", systemAvailable="
            + this.systemAvailable
            + ", validFrom="
            + this.validFrom
            + ", validTo="
            + this.validTo
            + ", translations$key="
            + this.translations$key
            + ", translations$value="
            + this.translations$value
            + ")";
      }
   }
}
