from django.db import models

from vbv_lernwelt.core.admin import User
from vbv_lernwelt.course.models import CourseCompletion, CourseCompletionStatus


class SelfEvaluationFeedback(models.Model):
    feedback_submitted = models.BooleanField(default=False)

    feedback_requester_user = models.ForeignKey(
        User, on_delete=models.CASCADE, related_name="feedback_requester_user"
    )

    feedback_provider_user = models.ForeignKey(
        User, on_delete=models.CASCADE, related_name="feedback_provider_user"
    )

    learning_unit = models.ForeignKey(
        "learnpath.LearningUnit", on_delete=models.CASCADE
    )

    @property
    def feedback_requester_results_url(self) -> str:
        url = self.learning_unit.get_evaluate_url()
        received_evaluation_step = len(self.learning_unit.performancecriteria_set.all())
        return f"{url}?step={received_evaluation_step}"

    @property
    def feedback_provider_evaluation_url(self) -> str:
        course, _, __ = self.learning_unit.get_frontend_url_parts()
        return f"/course/{course}/cockpit/mentor/self-evaluation-feedback/{self.learning_unit.id}"


class CourseCompletionFeedback(models.Model):
    feedback = models.ForeignKey(SelfEvaluationFeedback, on_delete=models.CASCADE)

    # the course completion has to be evaluated by the feedback provider
    course_completion = models.ForeignKey(CourseCompletion, on_delete=models.CASCADE)

    feedback_assessment = models.CharField(
        max_length=255,
        choices=[(status, status.value) for status in CourseCompletionStatus],
        default=CourseCompletionStatus.UNKNOWN.value,
    )
