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

import com.airlock.iam.base.api.domain.model.user.UserId;
import com.airlock.iam.common.api.domain.model.locking.LockReason;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import jakarta.annotation.Nullable;
import java.util.Date;
import java.util.Optional;

public final class UserLockState {
   private final UserId userId;
   private final boolean locked;
   private final Optional<LockReason> reason;
   private final Optional<Date> lockDate;
   private final boolean stateUpdated;

   private UserLockState(UserId userId, Optional<LockReason> reason, boolean locked, @Nullable Date lockDate, boolean stateUpdated) {
      this.userId = userId;
      this.locked = locked;
      this.reason = reason;
      this.lockDate = Optional.ofNullable(lockDate);
      this.stateUpdated = stateUpdated;
   }

   public boolean equalReason(LockReason lockReason) {
      return this.equalReason(lockReason.getResourceKey());
   }

   public boolean equalReason(String lockReason) {
      return this.reason.isPresent() && this.reason.get().getResourceKey().equals(lockReason);
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public UserId getUserId() {
      return this.userId;
   }

   @SuppressFBWarnings(justification = "generated code")
   public boolean isLocked() {
      return this.locked;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<LockReason> getReason() {
      return this.reason;
   }

   @SuppressFBWarnings(justification = "generated code")
   public Optional<Date> getLockDate() {
      return this.lockDate;
   }

   @SuppressFBWarnings(justification = "generated code")
   public boolean isStateUpdated() {
      return this.stateUpdated;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public boolean equals(Object o) {
      if (o == this) {
         return true;
      } else if (!(o instanceof UserLockState other)) {
         return false;
      } else {
         if (this.locked != other.locked) {
            return false;
         }

         if (this.stateUpdated != other.stateUpdated) {
            return false;
         }

         Object this$userId = this.userId;
         Object other$userId = other.userId;
         if (this$userId == null ? other$userId == null : this$userId.equals(other$userId)) {
            Object this$reason = this.reason;
            Object other$reason = other.reason;
            if (this$reason == null ? other$reason == null : this$reason.equals(other$reason)) {
               Object this$lockDate = this.lockDate;
               Object other$lockDate = other.lockDate;
               return this$lockDate == null ? other$lockDate == null : this$lockDate.equals(other$lockDate);
            } else {
               return false;
            }
         } else {
            return false;
         }
      }
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public int hashCode() {
      int PRIME = 59;
      int result = 1;
      result = result * 59 + (this.locked ? 79 : 97);
      result = result * 59 + (this.stateUpdated ? 79 : 97);
      Object $userId = this.userId;
      result = result * 59 + ($userId == null ? 43 : $userId.hashCode());
      Object $reason = this.reason;
      result = result * 59 + ($reason == null ? 43 : $reason.hashCode());
      Object $lockDate = this.lockDate;
      return result * 59 + ($lockDate == null ? 43 : $lockDate.hashCode());
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "UserLockState(userId="
         + this.getUserId()
         + ", locked="
         + this.isLocked()
         + ", reason="
         + this.getReason()
         + ", lockDate="
         + this.getLockDate()
         + ", stateUpdated="
         + this.isStateUpdated()
         + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class UserLockStateBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private UserId userId;
      @SuppressFBWarnings(justification = "generated code")
      private Optional<LockReason> reason;
      @SuppressFBWarnings(justification = "generated code")
      private boolean locked;
      @SuppressFBWarnings(justification = "generated code")
      private Date lockDate;
      @SuppressFBWarnings(justification = "generated code")
      private boolean stateUpdated;

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

      @SuppressFBWarnings(justification = "generated code")
      public UserLockState.UserLockStateBuilder userId(UserId userId) {
         this.userId = userId;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserLockState.UserLockStateBuilder reason(Optional<LockReason> reason) {
         this.reason = reason;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserLockState.UserLockStateBuilder locked(boolean locked) {
         this.locked = locked;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserLockState.UserLockStateBuilder lockDate(@Nullable Date lockDate) {
         this.lockDate = lockDate;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserLockState.UserLockStateBuilder stateUpdated(boolean stateUpdated) {
         this.stateUpdated = stateUpdated;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserLockState build() {
         return new UserLockState(this.userId, this.reason, this.locked, this.lockDate, this.stateUpdated);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "UserLockState.UserLockStateBuilder(userId="
            + this.userId
            + ", reason="
            + this.reason
            + ", locked="
            + this.locked
            + ", lockDate="
            + this.lockDate
            + ", stateUpdated="
            + this.stateUpdated
            + ")";
      }
   }
}
