package com.airlock.iam.common.application.configuration.user;

import com.airlock.iam.common.domain.model.user.PersistentUserPredicate;
import com.airlock.iam.common.domain.model.user.UserNotValidAnymorePredicate;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.IntegerProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "Returns true for users whose 'not valid after' fields lie in the past. If 'not valid after' is not set, the predicate is 'false'. The evaluation doesn't consider the current value of the 'valid' field."
)
public class UserNotValidAnymorePredicateConfig implements PersistentUserPredicateConfig {
   @IntegerProperty(
      description = "Number of days after 'not valid after' during which the predicate still returns 'true'. If not set, the grace period is implicitly set to 0.",
      displayName = "Grace Period [d]",
      minValue = 0,
      defaultValue = 0,
      exampleValues = {0, 7, 30},
      optional = true
   )
   private int gracePeriod;

   @Override
   public PersistentUserPredicate getLogic() {
      return UserNotValidAnymorePredicate.builder().gracePeriod(this.gracePeriod).build();
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public UserNotValidAnymorePredicateConfig(int gracePeriod) {
      this.gracePeriod = gracePeriod;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public static class UserNotValidAnymorePredicateConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private int gracePeriod;

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

      @SuppressFBWarnings(justification = "generated code")
      public UserNotValidAnymorePredicateConfig.UserNotValidAnymorePredicateConfigBuilder gracePeriod(int gracePeriod) {
         this.gracePeriod = gracePeriod;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserNotValidAnymorePredicateConfig build() {
         return new UserNotValidAnymorePredicateConfig(this.gracePeriod);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "UserNotValidAnymorePredicateConfig.UserNotValidAnymorePredicateConfigBuilder(gracePeriod=" + this.gracePeriod + ")";
      }
   }
}
