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.CustomStaticBooleanClaimExtractor;
import com.airlock.iam.oauth2.domain.model.claims.custom.CustomStaticBooleanClaimSettings;
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.BooleanProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(description = "A static boolean claim.", displayName = "Static Boolean Custom Claim")
@PluginLicenseRestriction(moduleAffiliation = "OAuthServer")
public final class CustomStaticBooleanClaimConfig extends GenericCustomClaimConfig {
   @BooleanProperty(
      description = "Static value of this claim. If the checkox is ticked, the claim will have the value <code>true</code>, otherwise <code>false</code>.",
      optional = true,
      defaultValue = "false"
   )
   private boolean staticValue;

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

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

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

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

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

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

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

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

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

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

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

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