package com.airlock.iam.common.domain.model.state;

import java.util.Optional;

public record InsertResult(boolean isLocked, Optional<String> insertedValue) implements RetryableOperation {
   public static InsertResult alreadyExists() {
      return new InsertResult(false, Optional.empty());
   }

   public static InsertResult inserted(String value) {
      return new InsertResult(false, Optional.of(value));
   }

   public static InsertResult locked() {
      return new InsertResult(true, Optional.empty());
   }

   public boolean valueWasInserted() {
      return this.insertedValue.isPresent();
   }

   @Override
   public boolean shouldRetry() {
      return this.isLocked;
   }
}
