import graphene

from vbv_lernwelt.assignment.graphql.types import (
    AssignmentCompletionObjectType,
    AssignmentObjectType,
    resolve_assignment_completion,
)
from vbv_lernwelt.assignment.models import Assignment
from vbv_lernwelt.course.graphql.types import resolve_course_page


class AssignmentQuery(object):
    assignment = graphene.Field(
        AssignmentObjectType, id=graphene.ID(), slug=graphene.String()
    )

    def resolve_assignment(root, info, id=None, slug=None):
        return resolve_course_page(Assignment, root, info, id=id, slug=slug)

    assignment_completion = graphene.Field(
        AssignmentCompletionObjectType,
        assignment_id=graphene.ID(required=True),
        course_session_id=graphene.ID(required=True),
        learning_content_page_id=graphene.ID(required=False),
        assignment_user_id=graphene.UUID(required=False),
    )

    def resolve_assignment_completion(
        root,
        info,
        assignment_id,
        course_session_id,
        learning_content_page_id=None,
        assignment_user_id=None,
        **kwargs,
    ):
        return resolve_assignment_completion(
            info,
            assignment_id,
            course_session_id,
            learning_content_page_id,
            assignment_user_id,
        )
