class ManagerPersonReview(models.Model):
    round = models.ForeignKey(Round, on_delete=models.PROTECT)
    reviewee = models.ForeignKey(User,
                                 on_delete=models.PROTECT,
                                 related_name='manager_person_reviews')
    sahabiness_rating = models.IntegerField(choices=Evaluation.choices(),
                                            null=True,
                                            blank=True)
    problem_solving_rating = models.IntegerField(choices=Evaluation.choices(),
                                                 null=True,
                                                 blank=True)
    execution_rating = models.IntegerField(choices=Evaluation.choices(),
                                           null=True,
                                           blank=True)
    thought_leadership_rating = models.IntegerField(
        choices=Evaluation.choices(), null=True, blank=True)
    leadership_rating = models.IntegerField(choices=Evaluation.choices(),
                                            null=True,
                                            blank=True)
    presence_rating = models.IntegerField(choices=Evaluation.choices(),
                                          null=True,
                                          blank=True)
    overall_rating = models.IntegerField(choices=Evaluation.choices(),
                                         null=True,
                                         blank=True)
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['created_at']
class ManagerProjectComment(models.Model):
    project_review = models.ForeignKey(ProjectReview, on_delete=models.PROTECT)
    rating = models.IntegerField(choices=Evaluation.choices(),
                                 blank=True,
                                 null=True)
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['created_at']
class ProjectReview(models.Model):
    project = models.ForeignKey(Project, on_delete=models.PROTECT)
    reviewee = models.ForeignKey(User, on_delete=models.PROTECT)
    text = models.TextField(blank=True, null=True)
    rating = models.IntegerField(choices=Evaluation.choices(),
                                 blank=True,
                                 null=True)
    reviewers = models.ManyToManyField(
        User, related_name='project_reviews_to_comment')
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ['created_at']
class PersonReview(models.Model):
    round = models.ForeignKey(Round, on_delete=models.PROTECT)
    reviewee = models.ForeignKey(User,
                                 on_delete=models.PROTECT,
                                 related_name='person_reviews')
    reviewer = models.ForeignKey(User,
                                 on_delete=models.PROTECT,
                                 related_name='authored_person_reviews')
    sahabiness_rating = models.IntegerField(choices=Evaluation.choices(),
                                            null=True,
                                            blank=True)
    sahabiness_comment = models.TextField(null=True, blank=True)
    problem_solving_rating = models.IntegerField(choices=Evaluation.choices(),
                                                 null=True,
                                                 blank=True)
    problem_solving_comment = models.TextField(null=True, blank=True)
    execution_rating = models.IntegerField(choices=Evaluation.choices(),
                                           null=True,
                                           blank=True)
    execution_comment = models.TextField(null=True, blank=True)
    thought_leadership_rating = models.IntegerField(
        choices=Evaluation.choices(), null=True, blank=True)
    thought_leadership_comment = models.TextField(null=True, blank=True)
    leadership_rating = models.IntegerField(choices=Evaluation.choices(),
                                            null=True,
                                            blank=True)
    leadership_comment = models.TextField(null=True, blank=True)
    presence_rating = models.IntegerField(choices=Evaluation.choices(),
                                          null=True,
                                          blank=True)
    presence_comment = models.TextField(null=True, blank=True)
    strengths = ArrayField(models.TextField(), size=3, null=True, blank=True)
    weaknesses = ArrayField(models.TextField(), size=3, null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)

    state = models.IntegerField(choices=State.choices(),
                                default=State.TODO.value)

    def is_self_review(self):
        return self.reviewee == self.reviewer

    class Meta:
        ordering = ['created_at']