package com.airlock.iam.factor.domain.service.fido;

import com.airlock.iam.base.api.domain.model.user.UserId;
import com.airlock.iam.core.misc.persistency.usereventbus.AfterUsernameChangeEvent;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import lombok.NonNull;

public final class UserIdChangeData {
   @NonNull
   private final UserId oldUserId;
   @NonNull
   private final UserId newUserId;

   public static UserIdChangeData userIdChange(AfterUsernameChangeEvent event) {
      return builder().oldUserId(UserId.userId(event.getOldUser().getName())).newUserId(UserId.userId(event.getNewUser().getName())).build();
   }

   @SuppressFBWarnings(justification = "generated code")
   UserIdChangeData(@NonNull UserId oldUserId, @NonNull UserId newUserId) {
      if (oldUserId == null) {
         throw new NullPointerException("oldUserId is marked non-null but is null");
      }

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

      this.oldUserId = oldUserId;
      this.newUserId = newUserId;
   }

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

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public UserId getOldUserId() {
      return this.oldUserId;
   }

   @NonNull
   @SuppressFBWarnings(justification = "generated code")
   public UserId getNewUserId() {
      return this.newUserId;
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "UserIdChangeData(oldUserId=" + this.getOldUserId() + ", newUserId=" + this.getNewUserId() + ")";
   }

   @SuppressFBWarnings(justification = "generated code")
   public static class UserIdChangeDataBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private UserId oldUserId;
      @SuppressFBWarnings(justification = "generated code")
      private UserId newUserId;

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

      @SuppressFBWarnings(justification = "generated code")
      public UserIdChangeData.UserIdChangeDataBuilder oldUserId(@NonNull UserId oldUserId) {
         if (oldUserId == null) {
            throw new NullPointerException("oldUserId is marked non-null but is null");
         }

         this.oldUserId = oldUserId;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserIdChangeData.UserIdChangeDataBuilder newUserId(@NonNull UserId newUserId) {
         if (newUserId == null) {
            throw new NullPointerException("newUserId is marked non-null but is null");
         }

         this.newUserId = newUserId;
         return this;
      }

      @SuppressFBWarnings(justification = "generated code")
      public UserIdChangeData build() {
         return new UserIdChangeData(this.oldUserId, this.newUserId);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "UserIdChangeData.UserIdChangeDataBuilder(oldUserId=" + this.oldUserId + ", newUserId=" + this.newUserId + ")";
      }
   }
}
