from django.test import TestCase

from vbv_lernwelt.course.creators.test_utils import (
    add_course_session_user,
    create_course,
    create_course_session,
    create_user,
)
from vbv_lernwelt.course.models import CourseSessionUser
from vbv_lernwelt.iam.permissions import course_session_permissions
from vbv_lernwelt.learning_mentor.models import LearningMentor


class ActionTestCase(TestCase):
    def setUp(self):
        self.course, _ = create_course("Test Course")
        self.course_session = create_course_session(
            course=self.course, title="Test Session"
        )

    def test_course_session_permissions(self):
        # GIVEN
        lm = create_user("mentor")
        LearningMentor.objects.create(
            mentor=lm,
            course=self.course,
        )

        participant = create_user("participant")
        add_course_session_user(
            self.course_session,
            participant,
            role=CourseSessionUser.Role.MEMBER,
        )

        trainer = create_user("trainer")
        add_course_session_user(
            self.course_session,
            trainer,
            role=CourseSessionUser.Role.EXPERT,
        )

        # WHEN
        mentor_actions = course_session_permissions(lm, self.course_session.id)
        participant_actions = course_session_permissions(
            participant, self.course_session.id
        )
        trainer_actions = course_session_permissions(trainer, self.course_session.id)

        # THEN
        self.assertEqual(len(mentor_actions), 0)
        self.assertEqual(participant_actions, ["complete-learning-content"])
        self.assertEqual(trainer_actions, ["complete-learning-content"])
