package com.airlock.iam.login.app.misc.configuration;

import com.airlock.iam.plugin.api.annotation.config.ConfigurationValidator;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import com.airlock.iam.plugin.api.config.ConfigurationContext;
import com.airlock.iam.plugin.api.config.ConfigurationEnvironment;
import com.airlock.iam.plugin.api.config.Environment;
import com.airlock.iam.plugin.api.config.PluginConfiguration;
import com.airlock.iam.plugin.api.exception.ConfigurationException;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Optional;

@Plugin(description = "Enables a global JWKS endpoint for all keys used by Loginapp for signing.", displayName = "Loginapp JWKS")
public class JwksLoginappConfig {
   @StringProperty(
      description = "If left empty the 'Cache-Control' response header is set to 'no-store, no-cache, must-revalidate'.\nIf configured, the 'Cache-Control' response header is set to the specified value.",
      displayName = "Cache-Control Response Header",
      exampleValues = "public, max-age=3600",
      optional = true
   )
   private String cacheControlResponseHeader;
   public static final String CACHE_CONTROL_RESPONSE_HEADER_PROPERTY = "cacheControlResponseHeader";

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

   @ConfigurationValidator
   public static void validateCacheControlHeader(PluginConfiguration config, ConfigurationEnvironment env, ConfigurationContext context, Environment valEnv) throws ConfigurationException {
      CacheControlHeaderValidator.checkIfAllowedHeaderValue(config, env, context, "cacheControlResponseHeader");
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public JwksLoginappConfig() {
   }

   @SuppressFBWarnings(justification = "generated code")
   public JwksLoginappConfig(String cacheControlResponseHeader) {
      this.cacheControlResponseHeader = cacheControlResponseHeader;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class JwksLoginappConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String cacheControlResponseHeader;

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

      @SuppressFBWarnings(justification = "generated code")
      public JwksLoginappConfig.JwksLoginappConfigBuilder cacheControlResponseHeader(String cacheControlResponseHeader) {
         this.cacheControlResponseHeader = cacheControlResponseHeader;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public JwksLoginappConfig build() {
         return new JwksLoginappConfig(this.cacheControlResponseHeader);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "JwksLoginappConfig.JwksLoginappConfigBuilder(cacheControlResponseHeader=" + this.cacheControlResponseHeader + ")";
      }
   }
}
