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

import com.airlock.iam.core.misc.impl.authen.radius.ReplyMessageAccessRejectRule;
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 reject reponse to an OTP authentication result type.",
   displayName = "OTP Check Access Reject Rule"
)
public class OtpCheckAccessRejectRule {
   @RegexProperty(
      description = "The regular expression matched against the reply message of the RADIUS access reject response.",
      caseSensitivity = CaseSensitivitySelector.CASE_INSENSITIVE,
      matchAgainstWholeInput = false,
      useDotAll = true,
      isMultiLine = true,
      optional = false
   )
   private Pattern pattern;
   @StringProperty(
      description = "Defines the authentication result type to be used if the reply message matches the configured pattern.",
      optional = false,
      allowedValues = {"Unspecified", "Token wrong", "Credential inactive"}
   )
   private String authenticationResult;

   public ReplyMessageAccessRejectRule toAccessRejectRule() {
      return new ReplyMessageAccessRejectRule(this.pattern, this.authenticationResult);
   }

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

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

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

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

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

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

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

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

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