package com.airlock.iam.flow.shared.application.configuration.radiusotp;

import com.airlock.iam.core.misc.impl.authen.radius.ReplyMessageAccessChallengeRule;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.RegexProperty;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import com.airlock.iam.plugin.api.annotation.property.RegexProperty.CaseSensitivitySelector;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.regex.Pattern;

@Plugin(
   description = "Maps the reply message from a RADIUS access challenge reponse to an OTP authentication result type.",
   displayName = "OTP Check Access Challenge Rule"
)
public class OtpCheckAccessChallengeRule {
   @RegexProperty(
      description = "The regular expression matched against the reply message of the RADIUS access challenge response.",
      caseSensitivity = CaseSensitivitySelector.CASE_INSENSITIVE,
      matchAgainstWholeInput = false,
      useDotAll = true,
      isMultiLine = true,
      optional = false
   )
   private Pattern pattern;
   @StringProperty(
      description = "Defines the authentication result when the reply message matches the configured pattern.",
      optional = false,
      allowedValues = {"Token required", "Token wrong, try again", "Next token required", "Credential not assigned"}
   )
   private String authenticationResult;

   public ReplyMessageAccessChallengeRule toAccessChallengeRule() {
      return new ReplyMessageAccessChallengeRule(this.pattern, this.authenticationResult);
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public OtpCheckAccessChallengeRule(Pattern pattern, String authenticationResult) {
      this.pattern = pattern;
      this.authenticationResult = authenticationResult;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class OtpCheckAccessChallengeRuleBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private Pattern pattern;
      @SuppressFBWarnings(justification = "generated code")
      private String authenticationResult;

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

      @SuppressFBWarnings(justification = "generated code")
      public OtpCheckAccessChallengeRule.OtpCheckAccessChallengeRuleBuilder pattern(Pattern pattern) {
         this.pattern = pattern;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OtpCheckAccessChallengeRule.OtpCheckAccessChallengeRuleBuilder authenticationResult(String authenticationResult) {
         this.authenticationResult = authenticationResult;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public OtpCheckAccessChallengeRule build() {
         return new OtpCheckAccessChallengeRule(this.pattern, this.authenticationResult);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "OtpCheckAccessChallengeRule.OtpCheckAccessChallengeRuleBuilder(pattern="
            + this.pattern
            + ", authenticationResult="
            + this.authenticationResult
            + ")";
      }
   }
}
