package com.airlock.iam.oauth2.application.configuration.claims;

import com.airlock.iam.oauth2.api.application.configuration.claims.ClaimConditionConfig;
import com.airlock.iam.oauth2.api.domain.model.claims.UserClaimExtractor;
import com.airlock.iam.oauth2.domain.model.claims.custom.CustomStaticStringClaimExtractor;
import com.airlock.iam.oauth2.domain.model.claims.custom.CustomStringClaimSettings;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.license.PluginLicenseRestriction;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(description = "A static string claim.", displayName = "Static String Custom Claim")
@PluginLicenseRestriction(moduleAffiliation = "OAuthServer")
public final class CustomStaticStringClaimConfig extends GenericCustomClaimConfig {
   @StringProperty(description = "Static value of this claim.", optional = false, exampleValues = "value")
   private String staticValue;

   @Override
   public UserClaimExtractor<?> logic() {
      CustomStringClaimSettings settings = new CustomStringClaimSettings(this.getClaimName(), this.getClaimCondition(), this.staticValue);
      return new CustomStaticStringClaimExtractor(() -> settings);
   }

   public String getStaticValue() {
      return this.staticValue;
   }

   public CustomStaticStringClaimConfig(String claimName, String staticValue, ClaimConditionConfig claimCondition) {
      super(claimName, claimCondition);
      this.staticValue = staticValue;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public static class CustomStaticStringClaimConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String claimName;
      @SuppressFBWarnings(justification = "generated code")
      private String staticValue;
      @SuppressFBWarnings(justification = "generated code")
      private ClaimConditionConfig claimCondition;

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

      @SuppressFBWarnings(justification = "generated code")
      public CustomStaticStringClaimConfig.CustomStaticStringClaimConfigBuilder claimName(String claimName) {
         this.claimName = claimName;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CustomStaticStringClaimConfig.CustomStaticStringClaimConfigBuilder staticValue(String staticValue) {
         this.staticValue = staticValue;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CustomStaticStringClaimConfig.CustomStaticStringClaimConfigBuilder claimCondition(ClaimConditionConfig claimCondition) {
         this.claimCondition = claimCondition;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public CustomStaticStringClaimConfig build() {
         return new CustomStaticStringClaimConfig(this.claimName, this.staticValue, this.claimCondition);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "CustomStaticStringClaimConfig.CustomStaticStringClaimConfigBuilder(claimName="
            + this.claimName
            + ", staticValue="
            + this.staticValue
            + ", claimCondition="
            + this.claimCondition
            + ")";
      }
   }
}
