package com.airlock.iam.application.parameters.domain.model;

import com.airlock.iam.system.config.ConfigFormat;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.net.URI;
import java.nio.file.Path;
import java.util.Optional;

public final class GlobalParameters {
   private final String javaOpts;
   private final Path tempDirectory;
   private final Path license;
   private final Path pidFile;
   private final String environmentId;
   private final IamTarget iamTarget;
   private final Path pluginConfig;
   private final ConfigFormat configFormat;
   private final URI sensitiveValuesConfig;
   private final IamMode iamMode;
   private final boolean disableAnalyticsOverride;

   public GlobalParameters(
      String javaOpts,
      Path tempDirectory,
      Path license,
      Path pidFile,
      String environmentId,
      IamTarget iamTarget,
      Path pluginConfig,
      ConfigFormat configFormat,
      URI sensitiveValuesConfig,
      IamMode iamMode,
      boolean disableAnalyticsOverride
   ) {
      this.javaOpts = javaOpts;
      this.tempDirectory = tempDirectory;
      this.license = license;
      this.pidFile = pidFile;
      this.environmentId = environmentId;
      this.iamTarget = iamTarget;
      this.pluginConfig = pluginConfig;
      this.configFormat = configFormat;
      this.sensitiveValuesConfig = sensitiveValuesConfig;
      this.iamMode = iamMode;
      this.disableAnalyticsOverride = disableAnalyticsOverride;
   }

   public Optional<Path> sensitiveValuesProviderConfig() {
      return this.sensitiveValuesFile("provider");
   }

   public Optional<Path> plainExternalSecrets() {
      return this.sensitiveValuesFile("secrets");
   }

   private Optional<Path> sensitiveValuesFile(String scheme) {
      return Optional.ofNullable(this.sensitiveValuesConfig)
         .filter(uri -> scheme.equals(uri.getScheme()))
         .map(URI::getSchemeSpecificPart)
         .map(x$0 -> Path.of(x$0));
   }

   public Optional<String> javaOpts() {
      return Optional.ofNullable(this.javaOpts);
   }

   public Optional<String> environmentId() {
      return Optional.ofNullable(this.environmentId);
   }

   public IamConfigRoot configRoot() {
      return this.iamTarget().configRoot();
   }

   public IamInstance instance() {
      return this.iamTarget().instance();
   }

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

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

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

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

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

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

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

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

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

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

         Object this$javaOpts = this.javaOpts;
         Object other$javaOpts = other.javaOpts;
         if (this$javaOpts == null ? other$javaOpts == null : this$javaOpts.equals(other$javaOpts)) {
            Object this$tempDirectory = this.tempDirectory;
            Object other$tempDirectory = other.tempDirectory;
            if (this$tempDirectory == null ? other$tempDirectory == null : this$tempDirectory.equals(other$tempDirectory)) {
               Object this$license = this.license;
               Object other$license = other.license;
               if (this$license == null ? other$license == null : this$license.equals(other$license)) {
                  Object this$pidFile = this.pidFile;
                  Object other$pidFile = other.pidFile;
                  if (this$pidFile == null ? other$pidFile == null : this$pidFile.equals(other$pidFile)) {
                     Object this$environmentId = this.environmentId;
                     Object other$environmentId = other.environmentId;
                     if (this$environmentId == null ? other$environmentId == null : this$environmentId.equals(other$environmentId)) {
                        Object this$iamTarget = this.iamTarget;
                        Object other$iamTarget = other.iamTarget;
                        if (this$iamTarget == null ? other$iamTarget == null : this$iamTarget.equals(other$iamTarget)) {
                           Object this$pluginConfig = this.pluginConfig;
                           Object other$pluginConfig = other.pluginConfig;
                           if (this$pluginConfig == null ? other$pluginConfig == null : this$pluginConfig.equals(other$pluginConfig)) {
                              Object this$configFormat = this.configFormat;
                              Object other$configFormat = other.configFormat;
                              if (this$configFormat == null ? other$configFormat == null : this$configFormat.equals(other$configFormat)) {
                                 Object this$sensitiveValuesConfig = this.sensitiveValuesConfig;
                                 Object other$sensitiveValuesConfig = other.sensitiveValuesConfig;
                                 if (this$sensitiveValuesConfig == null
                                    ? other$sensitiveValuesConfig == null
                                    : this$sensitiveValuesConfig.equals(other$sensitiveValuesConfig)) {
                                    Object this$iamMode = this.iamMode;
                                    Object other$iamMode = other.iamMode;
                                    return this$iamMode == null ? other$iamMode == null : this$iamMode.equals(other$iamMode);
                                 } 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.disableAnalyticsOverride ? 79 : 97);
      Object $javaOpts = this.javaOpts;
      result = result * 59 + ($javaOpts == null ? 43 : $javaOpts.hashCode());
      Object $tempDirectory = this.tempDirectory;
      result = result * 59 + ($tempDirectory == null ? 43 : $tempDirectory.hashCode());
      Object $license = this.license;
      result = result * 59 + ($license == null ? 43 : $license.hashCode());
      Object $pidFile = this.pidFile;
      result = result * 59 + ($pidFile == null ? 43 : $pidFile.hashCode());
      Object $environmentId = this.environmentId;
      result = result * 59 + ($environmentId == null ? 43 : $environmentId.hashCode());
      Object $iamTarget = this.iamTarget;
      result = result * 59 + ($iamTarget == null ? 43 : $iamTarget.hashCode());
      Object $pluginConfig = this.pluginConfig;
      result = result * 59 + ($pluginConfig == null ? 43 : $pluginConfig.hashCode());
      Object $configFormat = this.configFormat;
      result = result * 59 + ($configFormat == null ? 43 : $configFormat.hashCode());
      Object $sensitiveValuesConfig = this.sensitiveValuesConfig;
      result = result * 59 + ($sensitiveValuesConfig == null ? 43 : $sensitiveValuesConfig.hashCode());
      Object $iamMode = this.iamMode;
      return result * 59 + ($iamMode == null ? 43 : $iamMode.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "GlobalParameters(javaOpts="
         + this.javaOpts()
         + ", tempDirectory="
         + this.tempDirectory()
         + ", license="
         + this.license()
         + ", pidFile="
         + this.pidFile()
         + ", environmentId="
         + this.environmentId()
         + ", iamTarget="
         + this.iamTarget()
         + ", pluginConfig="
         + this.pluginConfig()
         + ", configFormat="
         + this.configFormat()
         + ", sensitiveValuesConfig="
         + this.sensitiveValuesConfig()
         + ", iamMode="
         + this.iamMode()
         + ", disableAnalyticsOverride="
         + this.disableAnalyticsOverride()
         + ")";
   }
}
