import graphene

from vbv_lernwelt.competence.graphql.types import (
    CompetenceCertificateListObjectType,
    CompetenceCertificateObjectType,
)
from vbv_lernwelt.competence.models import (
    CompetenceCertificate,
    CompetenceCertificateList,
)
from vbv_lernwelt.course.graphql.types import resolve_course_page


class CompetenceCertificateQuery(object):
    competence_certificate = graphene.Field(
        CompetenceCertificateObjectType, id=graphene.ID(), slug=graphene.String()
    )

    competence_certificate_list = graphene.Field(
        CompetenceCertificateListObjectType,
        id=graphene.ID(),
        slug=graphene.String(),
        course_id=graphene.ID(),
        course_slug=graphene.String(),
    )

    def resolve_competence_certificate(root, info, id=None, slug=None):
        return resolve_course_page(CompetenceCertificate, root, info, id=id, slug=slug)

    def resolve_competence_certificate_list(
        root, info, id=None, slug=None, course_id=None, course_slug=None
    ):
        return resolve_course_page(
            CompetenceCertificateList,
            root,
            info,
            id=id,
            slug=slug,
            course_id=course_id,
            course_slug=course_slug,
        )
