package com.airlock.iam.flow.domain.model.statemachine.runtime;

import com.airlock.iam.flow.api.application.configuration.step.FlowStepConfig;
import com.airlock.iam.flow.api.domain.model.step.FlowStep;
import com.airlock.iam.flow.api.domain.model.step.FlowStepConfigId;
import com.airlock.iam.flow.domain.model.statemachine.FlowState;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.inject.Provider;
import java.util.Optional;
import lombok.NonNull;

public final class FlowStateWithStep implements FlowState {
   @NonNull
   private String id;
   @NonNull
   private transient Provider<FlowStep> step;
   @NonNull
   private transient FlowStepConfig stepConfig;

   @Override
   public boolean hasStep() {
      return true;
   }

   @Override
   public FlowStepConfigId getConfigId() {
      return this.stepConfig.getConfigId();
   }

   @Override
   public Optional<FlowStepConfig> getStepConfig() {
      return Optional.of(this.stepConfig);
   }

   @Override
   public Optional<FlowStep> getStep() {
      return Optional.of((FlowStep)this.step.get());
   }

   @SuppressFBWarnings(justification = "generated code")
   public FlowStateWithStep(@NonNull String id, @NonNull Provider<FlowStep> step, @NonNull FlowStepConfig stepConfig) {
      if (id == null) {
         throw new NullPointerException("id is marked non-null but is null");
      }

      if (step == null) {
         throw new NullPointerException("step is marked non-null but is null");
      }

      if (stepConfig == null) {
         throw new NullPointerException("stepConfig is marked non-null but is null");
      }

      this.id = id;
      this.step = step;
      this.stepConfig = stepConfig;
   }

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "FlowStateWithStep(id=" + this.getId() + ")";
   }

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

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String getId() {
      return this.id;
   }
}
