# generated by datamodel-codegen:
#   filename:  tyx-document.schema.json
#   timestamp: 2025-10-22T13:26:50+00:00

from __future__ import annotations

from typing import Dict, List, Literal, Optional, Union

from pydantic import BaseModel, ConfigDict, Field, RootModel


class TyXTextNode(BaseModel):
    """
    A node describing text.
    """

    type: Literal["text"]
    text: str
    format: float


class TyXMathNode(BaseModel):
    """
    A node describing a math equation.
    """

    type: Literal["math"]
    typst: Optional[str] = None
    inline: Optional[bool] = None


class TyXLineBreakNode(BaseModel):
    """
    A line break node.
    """

    type: Literal["linebreak"]


class TyXHorizontalRuleNode(BaseModel):
    """
    A horizontal rule node.
    """

    type: Literal["horizontalrule"]


class TyXImageNode(BaseModel):
    """
    An image node.
    """

    type: Literal["image"]
    src: str


class TyXLengthValue(BaseModel):
    """
    An object representing Typst `relative` or `fraction` types.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    unit: Optional[str] = Field(
        None,
        description="The TyX length unit, one of 'pt', 'mm', 'cm', 'in', 'em', 'fr', '%'.",
    )
    value: Optional[str] = Field(None, description="The length numeric value.")
    type: Literal["length"]


class TyXBooleanValue(BaseModel):
    """
    An object representing Typst `bool` type.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    type: Literal["boolean"]
    value: Optional[bool] = None


class Indentation(BaseModel):
    """
    Optional indentation for paragraphs in the document.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    unit: Optional[str] = Field(
        None,
        description="The TyX length unit, one of 'pt', 'mm', 'cm', 'in', 'em', 'fr', '%'.",
    )
    value: Optional[str] = Field(None, description="The length numeric value.")


class NamedItem(BaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    type: str = Field(..., description="The TyX type of this parameter.")
    required: Optional[bool] = Field(
        None, description="Whether this parameter is required."
    )
    label: Optional[str] = Field(
        None, description="Optional label (usually name) of this parameter."
    )
    documentation: Optional[str] = Field(
        None, description="Optional documentation for this parameter to show on hover."
    )
    name: str


class ParameterDescription(BaseModel):
    """
    TyX specification for a function parameter.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    type: str = Field(..., description="The TyX type of this parameter.")
    required: Optional[bool] = Field(
        None, description="Whether this parameter is required."
    )
    label: Optional[str] = Field(
        None, description="Optional label (usually name) of this parameter."
    )
    documentation: Optional[str] = Field(
        None, description="Optional documentation for this parameter to show on hover."
    )


class FunctionDefinition(BaseModel):
    """
    TyX specification for a Typst function.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    positional: Optional[List[ParameterDescription]] = Field(
        None, description="Positional arguments to the function."
    )
    named: Optional[List[NamedItem]] = Field(
        None, description="Named arguments to the function."
    )
    inline: Optional[bool] = Field(
        None, description="Whether TyX should display the function as inline."
    )


class TyXDocumentSettings(BaseModel):
    """
    An object wrapping some common Typst document configuration options.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    root: Optional[str] = Field(
        None, description="The root directory for the Typst compiler."
    )
    fontPaths: Optional[List[str]] = Field(
        None, description="Additional font paths for the Typst compiler."
    )
    language: Optional[str] = Field(None, description="The language of the document.")
    paper: Optional[str] = Field(None, description="The paper size of the document.")
    flipped: Optional[bool] = Field(
        None, description="Whether the document's page is flipped."
    )
    justified: Optional[bool] = Field(
        None, description="Whether the document's text is justified."
    )
    indentation: Optional[Indentation] = Field(
        None, description="Optional indentation for paragraphs in the document."
    )
    columns: Optional[float] = Field(
        None, description="The amount of columns in the document."
    )
    functions: Optional[Dict[str, FunctionDefinition]] = Field(
        None, description="Additional TyX function definitions."
    )


class Content(BaseModel):
    """
    The serialized content of the editor.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    root: TyXRootNode


class TyXDocument(BaseModel):
    """
    An object representing an entire TyX document. Saved in `.tyx` files.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    field_schema: Optional[str] = Field(None, alias="$schema")
    version: str = Field(
        ..., description="The version of TyX in which the document was created."
    )
    preamble: Optional[str] = Field(
        None, description="Raw Typst code to insert before the content."
    )
    filename: Optional[str] = Field(
        None, description="The filename of the document, unused."
    )
    content: Optional[Content] = Field(
        None, description="The serialized content of the editor."
    )
    dirty: Optional[bool] = Field(
        None,
        description="Whether the document has been modified since loading, unused.",
    )
    settings: Optional[TyXDocumentSettings] = Field(
        None, description="The document's settings."
    )


class TyXRootNode(BaseModel):
    """
    The node at the root of a TyX document.
    """

    type: Literal["root"]
    children: List[TyXNode]
    direction: Optional[str] = None


class TyXNode(
    RootModel[
        Union[
            "TyXRootNode",
            "TyXParagraphNode",
            "TyXTextNode",
            "TyXMathNode",
            "TyXListItemNode",
            "TyXListNode",
            "TyXCodeNode",
            "TyXQuoteNode",
            "TyXTableNode",
            "TyXTableRowNode",
            "TyXTableCellNode",
            "TyXLineBreakNode",
            "TyXHorizontalRuleNode",
            "TyXTypstCodeNode",
            "TyXImageNode",
            "TyXLinkNode",
            "TyXHeadingNode",
            "TyXFunctionCallNode",
        ]
    ]
):
    root: Union[
        "TyXRootNode",
        "TyXParagraphNode",
        "TyXTextNode",
        "TyXMathNode",
        "TyXListItemNode",
        "TyXListNode",
        "TyXCodeNode",
        "TyXQuoteNode",
        "TyXTableNode",
        "TyXTableRowNode",
        "TyXTableCellNode",
        "TyXLineBreakNode",
        "TyXHorizontalRuleNode",
        "TyXTypstCodeNode",
        "TyXImageNode",
        "TyXLinkNode",
        "TyXHeadingNode",
        "TyXFunctionCallNode",
    ] = Field(..., description="Some TyX node.")


class TyXParagraphNode(BaseModel):
    """
    A node describing a paragraph.
    """

    type: Literal["paragraph"]
    children: List[TyXNode]
    format: str
    direction: Optional[str] = None


class TyXListItemNode(BaseModel):
    """
    A node describing a list item.
    """

    type: Literal["listitem"]
    children: List[TyXNode]


class TyXListNode(BaseModel):
    """
    A node describing a bullet or numbered list.
    """

    type: Literal["list"]
    children: List[TyXNode]
    listType: str
    start: float
    direction: Optional[str] = None


class TyXCodeNode(BaseModel):
    """
    A node describing a code block.
    """

    type: Literal["code"]
    children: List[TyXNode]
    language: Optional[str] = None


class TyXQuoteNode(BaseModel):
    """
    A node describing a block quote.
    """

    type: Literal["quote"]
    children: List[TyXNode]
    direction: Optional[str] = None


class TyXTableNode(BaseModel):
    """
    A node describing a table.
    """

    type: Literal["table"]
    children: List[TyXNode]
    direction: Optional[str] = None


class TyXTableRowNode(BaseModel):
    """
    A node describing a table row.
    """

    type: Literal["tablerow"]
    children: List[TyXNode]


class TyXTableCellNode(BaseModel):
    """
    A node describing a table cell.
    """

    type: Literal["tablecell"]
    children: List[TyXNode]
    direction: Optional[str] = None


class EditorState(BaseModel):
    root: TyXRootNode


class Text(BaseModel):
    editorState: EditorState


class TyXTypstCodeNode(BaseModel):
    """
    A raw Typst code node.
    """

    type: Literal["typstcode"]
    text: Text


class TyXLinkNode(BaseModel):
    """
    A link node.
    """

    type: Literal["link"]
    children: List[TyXNode]
    url: str


class TyXHeadingNode(BaseModel):
    """
    A heading node.
    """

    type: Literal["heading"]
    tag: str
    children: List[TyXNode]


class PositionParameters(BaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    type: Literal["content"]
    value: Optional[TyXRootNode] = None


class NamedParameters(BaseModel):
    model_config = ConfigDict(
        extra="forbid",
    )
    type: Literal["content"]
    value: Optional[TyXRootNode] = None


class TyXFunctionCallNode(BaseModel):
    """
    A function call node.
    """

    type: Literal["functioncall"]
    name: Optional[str] = None
    positionParameters: List[
        Union["TyXLengthValue", "TyXBooleanValue", "PositionParameters"]
    ]
    namedParameters: Dict[
        str, Union["TyXLengthValue", "TyXBooleanValue", "NamedParameters"]
    ]


Content.model_rebuild()
TyXRootNode.model_rebuild()
TyXNode.model_rebuild()
