"""
Generated by qenerate plugin=pydantic_v2. 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 Any, Optional, Union  # noqa: F401 # pylint: disable=W0611

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

DEFINITION = """
query ModuleIndex($course_id: ID!) {
    legacyNode(_id: $course_id, type: Course) {
        ... on Course {
            modulesConnection {
                nodes {
                    name
                    id
                    moduleItems {
                        content {
                            ... on File {
                                _id
                                displayName
                                createdAt
                                updatedAt
                                url
                                size
                                mimeClass
                                contentType
                            }
                            ... on Page {
                                _id
                                title
                                updatedAt
                                createdAt
                            }
                        }
                    }
                }
            }
        }
    }
}
"""


class ConfiguredBaseModel(BaseModel):
    class Config:
        extra = "forbid"


class Node(ConfiguredBaseModel): ...


class ModuleItemInterface(ConfiguredBaseModel): ...


class File(ModuleItemInterface):
    q_id: str = Field(..., alias="_id")
    display_name: Optional[str] = Field(..., alias="displayName")
    created_at: Optional[datetime] = Field(..., alias="createdAt")
    updated_at: Optional[datetime] = Field(..., alias="updatedAt")
    url: Optional[str] = Field(..., alias="url")
    size: Optional[str] = Field(..., alias="size")
    mime_class: Optional[str] = Field(..., alias="mimeClass")
    content_type: Optional[str] = Field(..., alias="contentType")


class Page(ModuleItemInterface):
    q_id: str = Field(..., alias="_id")
    title: Optional[str] = Field(..., alias="title")
    updated_at: Optional[datetime] = Field(..., alias="updatedAt")
    created_at: Optional[datetime] = Field(..., alias="createdAt")


class ModuleItem(ConfiguredBaseModel):
    content: Optional[Union[File, Page, ModuleItemInterface]] = Field(
        ..., alias="content"
    )


class Module(ConfiguredBaseModel):
    name: Optional[str] = Field(..., alias="name")
    q_id: str = Field(..., alias="id")
    module_items: Optional[list[ModuleItem]] = Field(..., alias="moduleItems")


class ModuleConnection(ConfiguredBaseModel):
    nodes: Optional[list[Optional[Module]]] = Field(..., alias="nodes")


class Course(Node):
    modules_connection: Optional[ModuleConnection] = Field(
        ..., alias="modulesConnection"
    )


class ModuleIndexQueryData(ConfiguredBaseModel):
    legacy_node: Optional[Union[Course, Node]] = Field(..., alias="legacyNode")


def query(query_func: Callable, **kwargs: Any) -> ModuleIndexQueryData:
    """
    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:
        ModuleIndexQueryData: queried data parsed into generated classes
    """
    raw_data: dict[Any, Any] = query_func(DEFINITION, **kwargs)
    return ModuleIndexQueryData(**raw_data)
