package com.airlock.iam.common.domain.model.logs;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import lombok.NonNull;

public final class Log {
   @NonNull
   private final Date timestamp;
   @NonNull
   private final String level;
   @NonNull
   private final String sessionId;
   @NonNull
   private final String requestId;
   @NonNull
   private final String sequenceNumber;
   @NonNull
   private final List<String> messageLines;
   @Nullable
   private final List<String> rawMessageLines;
   @NonNull
   private final String configContextIdentifier;
   @Nullable
   private final String clientIp;
   @NonNull
   private final LogSignatureVerification signatureVerification;
   private final boolean preformatted;

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public Date getTimestamp() {
      return this.timestamp;
   }

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

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

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

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public List<String> getMessageLines() {
      return this.messageLines;
   }

   @Nullable
   @SuppressFBWarnings(justification = "generated code")
   public List<String> getRawMessageLines() {
      return this.rawMessageLines;
   }

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

   @Nullable
   @SuppressFBWarnings(justification = "generated code")
   public String getClientIp() {
      return this.clientIp;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public LogSignatureVerification getSignatureVerification() {
      return this.signatureVerification;
   }

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

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

         Object this$timestamp = this.timestamp;
         Object other$timestamp = other.timestamp;
         if (this$timestamp == null ? other$timestamp == null : this$timestamp.equals(other$timestamp)) {
            Object this$level = this.level;
            Object other$level = other.level;
            if (this$level == null ? other$level == null : this$level.equals(other$level)) {
               Object this$sessionId = this.sessionId;
               Object other$sessionId = other.sessionId;
               if (this$sessionId == null ? other$sessionId == null : this$sessionId.equals(other$sessionId)) {
                  Object this$requestId = this.requestId;
                  Object other$requestId = other.requestId;
                  if (this$requestId == null ? other$requestId == null : this$requestId.equals(other$requestId)) {
                     Object this$sequenceNumber = this.sequenceNumber;
                     Object other$sequenceNumber = other.sequenceNumber;
                     if (this$sequenceNumber == null ? other$sequenceNumber == null : this$sequenceNumber.equals(other$sequenceNumber)) {
                        Object this$messageLines = this.messageLines;
                        Object other$messageLines = other.messageLines;
                        if (this$messageLines == null ? other$messageLines == null : this$messageLines.equals(other$messageLines)) {
                           Object this$rawMessageLines = this.rawMessageLines;
                           Object other$rawMessageLines = other.rawMessageLines;
                           if (this$rawMessageLines == null ? other$rawMessageLines == null : this$rawMessageLines.equals(other$rawMessageLines)) {
                              Object this$configContextIdentifier = this.configContextIdentifier;
                              Object other$configContextIdentifier = other.configContextIdentifier;
                              if (this$configContextIdentifier == null
                                 ? other$configContextIdentifier == null
                                 : this$configContextIdentifier.equals(other$configContextIdentifier)) {
                                 Object this$clientIp = this.clientIp;
                                 Object other$clientIp = other.clientIp;
                                 if (this$clientIp == null ? other$clientIp == null : this$clientIp.equals(other$clientIp)) {
                                    Object this$signatureVerification = this.signatureVerification;
                                    Object other$signatureVerification = other.signatureVerification;
                                    return this$signatureVerification == null
                                       ? other$signatureVerification == null
                                       : this$signatureVerification.equals(other$signatureVerification);
                                 } else {
                                    return false;
                                 }
                              } else {
                                 return false;
                              }
                           } 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;
      result = result * 59 + (this.preformatted ? 79 : 97);
      Object $timestamp = this.timestamp;
      result = result * 59 + ($timestamp == null ? 43 : $timestamp.hashCode());
      Object $level = this.level;
      result = result * 59 + ($level == null ? 43 : $level.hashCode());
      Object $sessionId = this.sessionId;
      result = result * 59 + ($sessionId == null ? 43 : $sessionId.hashCode());
      Object $requestId = this.requestId;
      result = result * 59 + ($requestId == null ? 43 : $requestId.hashCode());
      Object $sequenceNumber = this.sequenceNumber;
      result = result * 59 + ($sequenceNumber == null ? 43 : $sequenceNumber.hashCode());
      Object $messageLines = this.messageLines;
      result = result * 59 + ($messageLines == null ? 43 : $messageLines.hashCode());
      Object $rawMessageLines = this.rawMessageLines;
      result = result * 59 + ($rawMessageLines == null ? 43 : $rawMessageLines.hashCode());
      Object $configContextIdentifier = this.configContextIdentifier;
      result = result * 59 + ($configContextIdentifier == null ? 43 : $configContextIdentifier.hashCode());
      Object $clientIp = this.clientIp;
      result = result * 59 + ($clientIp == null ? 43 : $clientIp.hashCode());
      Object $signatureVerification = this.signatureVerification;
      return result * 59 + ($signatureVerification == null ? 43 : $signatureVerification.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "Log(timestamp="
         + this.getTimestamp()
         + ", level="
         + this.getLevel()
         + ", sessionId="
         + this.getSessionId()
         + ", requestId="
         + this.getRequestId()
         + ", sequenceNumber="
         + this.getSequenceNumber()
         + ", messageLines="
         + this.getMessageLines()
         + ", rawMessageLines="
         + this.getRawMessageLines()
         + ", configContextIdentifier="
         + this.getConfigContextIdentifier()
         + ", clientIp="
         + this.getClientIp()
         + ", signatureVerification="
         + this.getSignatureVerification()
         + ", preformatted="
         + this.isPreformatted()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public Log(
      @NonNull Date timestamp,
      @NonNull String level,
      @NonNull String sessionId,
      @NonNull String requestId,
      @NonNull String sequenceNumber,
      @NonNull List<String> messageLines,
      @Nullable List<String> rawMessageLines,
      @NonNull String configContextIdentifier,
      @Nullable String clientIp,
      @NonNull LogSignatureVerification signatureVerification,
      boolean preformatted
   ) {
      if (timestamp == null) {
         throw new NullPointerException("timestamp is marked non-null but is null");
      }

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

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

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

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

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

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

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

      this.timestamp = timestamp;
      this.level = level;
      this.sessionId = sessionId;
      this.requestId = requestId;
      this.sequenceNumber = sequenceNumber;
      this.messageLines = messageLines;
      this.rawMessageLines = rawMessageLines;
      this.configContextIdentifier = configContextIdentifier;
      this.clientIp = clientIp;
      this.signatureVerification = signatureVerification;
      this.preformatted = preformatted;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class LogBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Date timestamp;
      @SuppressFBWarnings(justification = "generated code")
      private String level;
      @SuppressFBWarnings(justification = "generated code")
      private String sessionId;
      @SuppressFBWarnings(justification = "generated code")
      private String requestId;
      @SuppressFBWarnings(justification = "generated code")
      private String sequenceNumber;
      @SuppressFBWarnings(justification = "generated code")
      private ArrayList<String> messageLines;
      @SuppressFBWarnings(justification = "generated code")
      private ArrayList<String> rawMessageLines;
      @SuppressFBWarnings(justification = "generated code")
      private String configContextIdentifier;
      @SuppressFBWarnings(justification = "generated code")
      private String clientIp;
      @SuppressFBWarnings(justification = "generated code")
      private LogSignatureVerification signatureVerification;
      @SuppressFBWarnings(justification = "generated code")
      private boolean preformatted;

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

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

         this.timestamp = timestamp;
         return this;
      }

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

         this.level = level;
         return this;
      }

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

         this.sessionId = sessionId;
         return this;
      }

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

         this.requestId = requestId;
         return this;
      }

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

         this.sequenceNumber = sequenceNumber;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Log.LogBuilder messageLine(String messageLine) {
         if (this.messageLines == null) {
            this.messageLines = new ArrayList<>();
         }

         this.messageLines.add(messageLine);
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Log.LogBuilder messageLines(Collection<? extends String> messageLines) {
         if (messageLines == null) {
            throw new NullPointerException("messageLines cannot be null");
         }

         if (this.messageLines == null) {
            this.messageLines = new ArrayList<>();
         }

         this.messageLines.addAll(messageLines);
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Log.LogBuilder clearMessageLines() {
         if (this.messageLines != null) {
            this.messageLines.clear();
         }

         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Log.LogBuilder rawMessageLine(String rawMessageLine) {
         if (this.rawMessageLines == null) {
            this.rawMessageLines = new ArrayList<>();
         }

         this.rawMessageLines.add(rawMessageLine);
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Log.LogBuilder rawMessageLines(Collection<? extends String> rawMessageLines) {
         if (rawMessageLines == null) {
            throw new NullPointerException("rawMessageLines cannot be null");
         }

         if (this.rawMessageLines == null) {
            this.rawMessageLines = new ArrayList<>();
         }

         this.rawMessageLines.addAll(rawMessageLines);
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Log.LogBuilder clearRawMessageLines() {
         if (this.rawMessageLines != null) {
            this.rawMessageLines.clear();
         }

         return this;
      }

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

         this.configContextIdentifier = configContextIdentifier;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Log.LogBuilder clientIp(@Nullable String clientIp) {
         this.clientIp = clientIp;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Log.LogBuilder signatureVerification(@NonNull LogSignatureVerification signatureVerification) {
         if (signatureVerification == null) {
            throw new NullPointerException("signatureVerification is marked non-null but is null");
         }

         this.signatureVerification = signatureVerification;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Log.LogBuilder preformatted(boolean preformatted) {
         this.preformatted = preformatted;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public Log build() {
         List messageLines = switch (this.messageLines == null ? 0 : this.messageLines.size()) {
            case 0 -> Collections.emptyList();
            case 1 -> Collections.singletonList(this.messageLines.get(0));
            default -> Collections.unmodifiableList(new ArrayList<>(this.messageLines));
         };

         return new Log(
            this.timestamp,
            this.level,
            this.sessionId,
            this.requestId,
            this.sequenceNumber,
            messageLines,
            switch (this.rawMessageLines == null ? 0 : this.rawMessageLines.size()) {
               case 0 -> Collections.emptyList();
               case 1 -> Collections.singletonList(this.rawMessageLines.get(0));
               default -> Collections.unmodifiableList(new ArrayList<>(this.rawMessageLines));
            },
            this.configContextIdentifier,
            this.clientIp,
            this.signatureVerification,
            this.preformatted
         );
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "Log.LogBuilder(timestamp="
            + this.timestamp
            + ", level="
            + this.level
            + ", sessionId="
            + this.sessionId
            + ", requestId="
            + this.requestId
            + ", sequenceNumber="
            + this.sequenceNumber
            + ", messageLines="
            + this.messageLines
            + ", rawMessageLines="
            + this.rawMessageLines
            + ", configContextIdentifier="
            + this.configContextIdentifier
            + ", clientIp="
            + this.clientIp
            + ", signatureVerification="
            + this.signatureVerification
            + ", preformatted="
            + this.preformatted
            + ")";
      }
   }
}
