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

import com.airlock.iam.flow.api.application.configuration.selection.FlowConditionConfig;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.PluginProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "<p>This condition is met if the user never logged in on the current device.</p><p>Device recognition is based on a cookie configured in the 'Cookie Settings'. A device is considered new for a user if the cookie is either missing or does not contain information about a prior login for that specific user.</p><p>To use this condition effectively: <ul><li>A 'Login from new Device Step' must be configured in the authentication flow. Without it, the condition always evaluates to 'true'.</li><li>This condition should be evaluated before the 'Login from new Device Step' is executed, otherwise the condition always evaluates to 'false'.</li></ul></p>"
)
public final class NewDeviceConditionConfig implements FlowConditionConfig {
   static final String COOKIE_SETTINGS_DISPLAY_NAME = "Cookie Settings";
   static final String LOGIN_FROM_NEW_DEVICE_STEP_DISPLAY_NAME = "Login from new Device Step";
   @PluginProperty(description = "Configures the cookie that stores information about users who have logged in on a device.", optional = false)
   private NewDeviceCookieConfig cookieSettings;

   public NewDeviceCookieConfig getCookieSettings() {
      return this.cookieSettings;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public NewDeviceConditionConfig(NewDeviceCookieConfig cookieSettings) {
      this.cookieSettings = cookieSettings;
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class NewDeviceConditionConfigBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private NewDeviceCookieConfig cookieSettings;

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

      @SuppressFBWarnings(justification = "generated code")
      public NewDeviceConditionConfig.NewDeviceConditionConfigBuilder cookieSettings(NewDeviceCookieConfig cookieSettings) {
         this.cookieSettings = cookieSettings;
         return this;
      }

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

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "NewDeviceConditionConfig.NewDeviceConditionConfigBuilder(cookieSettings=" + this.cookieSettings + ")";
      }
   }
}
