package com.airlock.iam.flow.application.configuration.redflag;

import com.airlock.iam.flow.api.application.configuration.redflag.RedFlagConfig;
import com.airlock.iam.flow.api.domain.model.redflag.RedFlag;
import com.airlock.iam.plugin.api.annotation.config.Plugin;
import com.airlock.iam.plugin.api.annotation.property.StringProperty;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

@Plugin(
   description = "A step can raise a red flag to signal to a later step that some action must be performed before the flow can succeed.<p>Example: the password check step raises a red flag if a mandatory password change must be performed. A step later in the flow requires the user to change his password if this red flag is raised. If no subsequent step handles the red flag, the flow fails.</p>",
   displayName = "Red Flag"
)
public final class RedFlagConfigImpl implements RedFlagConfig {
   @StringProperty(description = "The name of the red flag.", optional = false)
   private String name;

   @Override
   public RedFlag toRedFlag() {
      return new RedFlag(this.getName());
   }

   @Override
   public String getName() {
      return this.name;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   public RedFlagConfigImpl(String name) {
      this.name = name;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof RedFlagConfigImpl other)) {
         return false;
      } else {
         Object this$name = this.name;
         Object other$name = other.name;
         return this$name == null ? other$name == null : this$name.equals(other$name);
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public int hashCode() {
      int PRIME = 59;
      int result = 1;
      Object $name = this.name;
      return result * 59 + ($name == null ? 43 : $name.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class RedFlagConfigImplBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String name;

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

      @SuppressFBWarnings(justification = "generated code")
      public RedFlagConfigImpl.RedFlagConfigImplBuilder name(String name) {
         this.name = name;
         return this;
      }

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

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "RedFlagConfigImpl.RedFlagConfigImplBuilder(name=" + this.name + ")";
      }
   }
}
