package com.airlock.iam.login.application.configuration.location.interpret;

import com.airlock.iam.login.api.application.configuration.location.interpret.LocationInterpretersConfig;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.PluginMapProperty;
import com.airlock.iam.plugin.api.annotation.property.RegexProperty;
import com.airlock.iam.plugin.api.annotation.property.RegexProperty.CaseSensitivitySelector;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Map;
import java.util.regex.Pattern;

@Plugin(
   description = "<p>Analyzes an URI sent to the <tt>/&lt;loginapp-uri&gt;/rest/public/authentication/location/interpret</tt> endpoint\nand if it matches the specified pattern, returns a set of values to the client.</p>\n<p>This could be the display language or other information extracted from the URI, that can be used by the\nclient before showing its UI.</p>",
   displayName = "Location Interpretations Configuration"
)
public class LocationInterpretersConfigImpl implements LocationInterpretersConfig {
   @RegexProperty(
      displayName = "URI Pattern",
      description = "The URI pattern (regular expression pattern) the provided URI must match in order to use the interpreters configured below. The matching is case-insensitive.",
      optional = true,
      defaultValue = ".*",
      exampleValues = {".*", "https://host:8080/app/.*"},
      caseSensitivity = CaseSensitivitySelector.CASE_INSENSITIVE
   )
   private Pattern uriPattern;
   @PluginMapProperty(
      description = "<p>The endpoint returns a JSON map of key/values that have been extracted or derived from the given URI.</p><p>This map specifies the keys returned and a corresponding plugin defining the logic to derive the value. For example, the key 'lang' could be mapped to a plugin that extracts a user language from the URI.</p><p>The resulting map of all key/value pairs is returned to the REST client.</p>",
      minElements = 1,
      optional = false
   )
   private Map<String, LocationInterpreterConfig> locationInterpreterConfigs;

   public Pattern getUriPattern() {
      return this.uriPattern;
   }

   public Map<String, LocationInterpreterConfig> getLocationInterpreterConfigs() {
      return this.locationInterpreterConfigs;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public LocationInterpretersConfigImpl(Pattern uriPattern, Map<String, LocationInterpreterConfig> locationInterpreterConfigs) {
      this.uriPattern = uriPattern;
      this.locationInterpreterConfigs = locationInterpreterConfigs;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class LocationInterpretersConfigImplBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Pattern uriPattern;
      @SuppressFBWarnings(justification = "generated code")
      private Map<String, LocationInterpreterConfig> locationInterpreterConfigs;

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

      @SuppressFBWarnings(justification = "generated code")
      public LocationInterpretersConfigImpl.LocationInterpretersConfigImplBuilder uriPattern(Pattern uriPattern) {
         this.uriPattern = uriPattern;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public LocationInterpretersConfigImpl.LocationInterpretersConfigImplBuilder locationInterpreterConfigs(
         Map<String, LocationInterpreterConfig> locationInterpreterConfigs
      ) {
         this.locationInterpreterConfigs = locationInterpreterConfigs;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public LocationInterpretersConfigImpl build() {
         return new LocationInterpretersConfigImpl(this.uriPattern, this.locationInterpreterConfigs);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "LocationInterpretersConfigImpl.LocationInterpretersConfigImplBuilder(uriPattern="
            + this.uriPattern
            + ", locationInterpreterConfigs="
            + this.locationInterpreterConfigs
            + ")";
      }
   }
}
