package com.airlock.iam.common.infrastructure.state.redis;

import com.airlock.iam.core.misc.util.config.Config;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.UUID;

final class LockOwnerId {
   private static final String LOCK_OWNER_PREFIX = "lock-owner-";
   private static LockOwnerId instance;
   private final String value;

   private LockOwnerId(String value) {
      this.value = value;
   }

   public static synchronized LockOwnerId getInstance() {
      if (instance == null) {
         instance = new LockOwnerId(buildId());
      }

      return instance;
   }

   private static String buildId() {
      return "lock-owner-" + Config.getAppIdentifier().id() + "-" + UUID.randomUUID().toString();
   }

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

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

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

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