from django.urls import reverse
from rest_framework import status
from rest_framework.test import APITestCase

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


class ProfileViewTest(APITestCase):
    def setUp(self) -> None:
        self.course, _ = create_course("Test Course")
        self.course_session = create_course_session(
            course=self.course, title="Test Session"
        )

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

        self.client.force_login(self.user)

    def test_user_profile(self) -> None:
        # GIVEN
        url = reverse(
            "get_profile_view",
            kwargs={
                "course_session_id": self.course_session.id,
                "user_id": self.user.id,
            },
        )

        # WHEN
        response = self.client.get(url)

        # THEN
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        profile = response.data
        self.assertEqual(
            profile,
            {
                "id": str(self.user.id),
                "first_name": self.user.first_name,
                "last_name": self.user.last_name,
                "email": self.user.email,
                "username": self.user.username,
                "avatar_url": "/static/avatars/myvbv-default-avatar.png",
                "organisation": None,
                "is_superuser": False,
                "course_session_experts": [],
                "language": "de",
                "invoice_address": "prv",
                "street": "",
                "street_number": "",
                "postal_code": "",
                "city": "",
                "country": None,
                "organisation_detail_name": "",
                "organisation_street": "",
                "organisation_street_number": "",
                "organisation_postal_code": "",
                "organisation_city": "",
                "organisation_country": None,
            },
        )
