"""
Generated by qenerate plugin=pydantic_v1. DO NOT MODIFY MANUALLY!
"""
from collections.abc import Callable  # noqa: F401 # pylint: disable=W0611
from datetime import datetime  # noqa: F401 # pylint: disable=W0611
from enum import Enum  # noqa: F401 # pylint: disable=W0611
from typing import (  # noqa: F401 # pylint: disable=W0611
    Any,
    Optional,
    Union,
)

from pydantic import (  # noqa: F401 # pylint: disable=W0611
    BaseModel,
    Extra,
    Field,
    Json,
)

from qcanvas.queries.canvas_course_data import CanvasCourseData

DEFINITION = """
fragment CanvasCourseData on Course {
    _id
#    id
    name
    courseNickname
    term {
        endAt
        startAt
        name
        id
    }
    assignmentsConnection @include(if: $detailed) {
        nodes {
            description
            courseId
            dueAt
            createdAt
            id
            name
            position
            updatedAt
        }
    }
    modulesConnection @include(if: $detailed) {
        nodes {
            name
            id
            moduleItems {
                content {
                    ... on File {
                        _id
                        displayName
                        createdAt
                        updatedAt
                        url
                        size
                        mimeClass
                        contentType
                    }
                    ... on Page {
                        _id
                        title
                        updatedAt
                        createdAt
                    }
                }
            }
        }
    }
}

query AllCourses($detailed: Boolean!) {
  allCourses {
    ...CanvasCourseData
  }
}
"""


class ConfiguredBaseModel(BaseModel):
    class Config:
        smart_union = True
        extra = Extra.forbid


class AllCoursesQueryData(ConfiguredBaseModel):
    all_courses: Optional[list[CanvasCourseData]] = Field(..., alias="allCourses")


def query(query_func: Callable, **kwargs: Any) -> AllCoursesQueryData:
    """
    This is a convenience function which queries and parses the data into
    concrete types. It should be compatible with most GQL clients.
    You do not have to use it to consume the generated data classes.
    Alternatively, you can also mime and alternate the behavior
    of this function in the caller.

    Parameters:
        query_func (Callable): Function which queries your GQL Server
        kwargs: optional arguments that will be passed to the query function

    Returns:
        AllCoursesQueryData: queried data parsed into generated classes
    """
    raw_data: dict[Any, Any] = query_func(DEFINITION, **kwargs)
    return AllCoursesQueryData(**raw_data)
