package com.airlock.iam.common.domain.model.token.secretquestions;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.Date;
import org.apache.commons.lang3.StringUtils;

public class SecretQuestionAnswer {
   private final String questionResourceKey;
   private final String answer;
   private String userId;

   public SecretQuestionAnswer(String questionResourceKey, String answer) {
      this.questionResourceKey = questionResourceKey;
      this.answer = answer;
   }

   public boolean isSet() {
      return StringUtils.isNotBlank(this.answer);
   }

   public boolean hasQuestionResourceKey() {
      return StringUtils.isNotBlank(this.questionResourceKey);
   }

   public SecretQuestionAnswer withUserId(String newUserId) {
      return this.toBuilder().userId(newUserId).build();
   }

   public SecretQuestion.SecretQuestionBuilder toSecretQuestion() {
      return SecretQuestion.builder().questionResourceKey(this.questionResourceKey).numberOfFailedAttempts(0).creationDate(new Date()).isBlocked(false);
   }

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

   @SuppressFBWarnings(justification = "generated code")
   public SecretQuestionAnswer.SecretQuestionAnswerBuilder toBuilder() {
      return new SecretQuestionAnswer.SecretQuestionAnswerBuilder().questionResourceKey(this.questionResourceKey).answer(this.answer).userId(this.userId);
   }

   @SuppressFBWarnings(justification = "generated code")
   public SecretQuestionAnswer(String questionResourceKey, String answer, String userId) {
      this.questionResourceKey = questionResourceKey;
      this.answer = answer;
      this.userId = userId;
   }

   @SuppressFBWarnings(justification = "generated code")
   @Override
   public String toString() {
      return "SecretQuestionAnswer(questionResourceKey="
         + this.getQuestionResourceKey()
         + ", answer="
         + this.getAnswer()
         + ", userId="
         + this.getUserId()
         + ")";
   }

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

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

   @SuppressFBWarnings(justification = "generated code")
   protected boolean canEqual(Object other) {
      return other instanceof SecretQuestionAnswer;
   }

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

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

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

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

   @SuppressFBWarnings(justification = "generated code")
   public static class SecretQuestionAnswerBuilder {
      @SuppressFBWarnings(justification = "generated code")
      private String questionResourceKey;
      @SuppressFBWarnings(justification = "generated code")
      private String answer;
      @SuppressFBWarnings(justification = "generated code")
      private String userId;

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

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

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

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

      @SuppressFBWarnings(justification = "generated code")
      public SecretQuestionAnswer build() {
         return new SecretQuestionAnswer(this.questionResourceKey, this.answer, this.userId);
      }

      @SuppressFBWarnings(justification = "generated code")
      @Override
      public String toString() {
         return "SecretQuestionAnswer.SecretQuestionAnswerBuilder(questionResourceKey="
            + this.questionResourceKey
            + ", answer="
            + this.answer
            + ", userId="
            + this.userId
            + ")";
      }
   }
}
