package com.airlock.iam.plugin.framework.misc.config;

import com.airlock.iam.plugin.api.config.ConfigurationEnvironment;
import com.airlock.iam.plugin.api.config.Environment;
import com.google.common.collect.ImmutableList;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import java.nio.file.Path;
import java.util.List;

public final class ValidationEnvironment {
   @Nullable
   private final Environment environment;
   private final boolean validateExternalSecretsKeys;
   private final List<String> externalSecretsKeys;
   @Nullable
   private final ConfigurationEnvironment instanceEnvironment;
   private final Path rootDir;

   public ValidationEnvironment(
      Path rootDir, @Nullable Environment environment, @Nullable ConfigurationEnvironment instanceEnvironment, @Nullable List<String> externalSecretsKeys
   ) {
      this.environment = environment;
      this.instanceEnvironment = instanceEnvironment;
      this.rootDir = rootDir;
      if (externalSecretsKeys == null) {
         this.externalSecretsKeys = ImmutableList.of();
         this.validateExternalSecretsKeys = false;
      } else {
         this.externalSecretsKeys = ImmutableList.copyOf(externalSecretsKeys);
         this.validateExternalSecretsKeys = environment == Environment.CURRENT_VM;
      }
   }

   public boolean externalSecretKeyExists(String externalSecretKey) {
      return this.externalSecretsKeys.contains(externalSecretKey);
   }

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

   @Nullable
   @SuppressFBWarnings(justification = "generated code")
   public Environment environment() {
      return this.environment;
   }

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

   @Nullable
   @SuppressFBWarnings(justification = "generated code")
   public ConfigurationEnvironment instanceEnvironment() {
      return this.instanceEnvironment;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Path rootDir() {
      return this.rootDir;
   }

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

         Object this$environment = this.environment;
         Object other$environment = other.environment;
         if (this$environment == null ? other$environment == null : this$environment.equals(other$environment)) {
            Object this$externalSecretsKeys = this.externalSecretsKeys;
            Object other$externalSecretsKeys = other.externalSecretsKeys;
            if (this$externalSecretsKeys == null ? other$externalSecretsKeys == null : this$externalSecretsKeys.equals(other$externalSecretsKeys)) {
               Object this$instanceEnvironment = this.instanceEnvironment;
               Object other$instanceEnvironment = other.instanceEnvironment;
               if (this$instanceEnvironment == null ? other$instanceEnvironment == null : this$instanceEnvironment.equals(other$instanceEnvironment)) {
                  Object this$rootDir = this.rootDir;
                  Object other$rootDir = other.rootDir;
                  return this$rootDir == null ? other$rootDir == null : this$rootDir.equals(other$rootDir);
               } 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.validateExternalSecretsKeys ? 79 : 97);
      Object $environment = this.environment;
      result = result * 59 + ($environment == null ? 43 : $environment.hashCode());
      Object $externalSecretsKeys = this.externalSecretsKeys;
      result = result * 59 + ($externalSecretsKeys == null ? 43 : $externalSecretsKeys.hashCode());
      Object $instanceEnvironment = this.instanceEnvironment;
      result = result * 59 + ($instanceEnvironment == null ? 43 : $instanceEnvironment.hashCode());
      Object $rootDir = this.rootDir;
      return result * 59 + ($rootDir == null ? 43 : $rootDir.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "ValidationEnvironment(environment="
         + this.environment()
         + ", validateExternalSecretsKeys="
         + this.validateExternalSecretsKeys()
         + ", externalSecretsKeys="
         + this.externalSecretsKeys
         + ", instanceEnvironment="
         + this.instanceEnvironment()
         + ", rootDir="
         + this.rootDir()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class ValidationEnvironmentBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Path rootDir;
      @SuppressFBWarnings(justification = "generated code")
      private Environment environment;
      @SuppressFBWarnings(justification = "generated code")
      private ConfigurationEnvironment instanceEnvironment;
      @SuppressFBWarnings(justification = "generated code")
      private List<String> externalSecretsKeys;

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

      @SuppressFBWarnings(justification = "generated code")
      public ValidationEnvironment.ValidationEnvironmentBuilder rootDir(Path rootDir) {
         this.rootDir = rootDir;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public ValidationEnvironment.ValidationEnvironmentBuilder environment(@Nullable Environment environment) {
         this.environment = environment;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public ValidationEnvironment.ValidationEnvironmentBuilder instanceEnvironment(@Nullable ConfigurationEnvironment instanceEnvironment) {
         this.instanceEnvironment = instanceEnvironment;
         return this;
      }

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

      @SuppressFBWarnings(justification = "generated code")
      public ValidationEnvironment build() {
         return new ValidationEnvironment(this.rootDir, this.environment, this.instanceEnvironment, this.externalSecretsKeys);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "ValidationEnvironment.ValidationEnvironmentBuilder(rootDir="
            + this.rootDir
            + ", environment="
            + this.environment
            + ", instanceEnvironment="
            + this.instanceEnvironment
            + ", externalSecretsKeys="
            + this.externalSecretsKeys
            + ")";
      }
   }
}
