# generated by datamodel-codegen:
#   filename:  nbformat.v4.schema.json
#   timestamp: 2025-08-29T01:57:28+00:00

from __future__ import annotations

from typing import Annotated, Any, Literal

from pydantic import BaseModel, ConfigDict, Field, RootModel


class Kernelspec(BaseModel):
    """
    Kernel information.
    """

    name: str
    """
    Name of the kernel specification.
    """
    display_name: str
    """
    Name to display in UI.
    """


class LanguageInfo(BaseModel):
    """
    Kernel information.
    """

    name: str
    """
    The programming language which this kernel runs.
    """
    codemirror_mode: str | dict[str, Any] | None = None
    """
    The codemirror mode to use for code in this language.
    """
    file_extension: str | None = None
    """
    The file extension for files in this language.
    """
    mimetype: str | None = None
    """
    The mimetype corresponding to files in this language.
    """
    pygments_lexer: str | None = None
    """
    The pygments lexer to use for code in this language.
    """


class Metadata(BaseModel):
    """
    Notebook root-level metadata.
    """

    model_config = ConfigDict(
        extra="allow",
    )
    kernelspec: Kernelspec | None = None
    """
    Kernel information.
    """
    language_info: LanguageInfo | None = None
    """
    Kernel information.
    """
    orig_nbformat: Annotated[int | None, Field(ge=1)] = None
    """
    Original notebook format (major number) before converting the notebook between versions. This should never be written to a file.
    """
    title: str | None = None
    """
    The title of the notebook document
    """
    authors: list | None = None
    """
    The author(s) of the notebook document
    """


class Execution(BaseModel):
    """
    Execution time for the code in the cell. This tracks time at which messages are received from iopub or shell channels
    """

    model_config = ConfigDict(
        extra="allow",
    )
    iopub_execute_input: Annotated[str | None, Field(alias="iopub.execute_input")] = (
        None
    )
    """
    header.date (in ISO 8601 format) of iopub channel's execute_input message. It indicates the time at which the kernel broadcasts an execute_input message to connected frontends
    """
    iopub_status_busy: Annotated[str | None, Field(alias="iopub.status.busy")] = None
    """
    header.date (in ISO 8601 format) of iopub channel's kernel status message when the status is 'busy'
    """
    shell_execute_reply: Annotated[str | None, Field(alias="shell.execute_reply")] = (
        None
    )
    """
    header.date (in ISO 8601 format) of the shell channel's execute_reply message. It indicates the time at which the execute_reply message was created
    """
    iopub_status_idle: Annotated[str | None, Field(alias="iopub.status.idle")] = None
    """
    header.date (in ISO 8601 format) of iopub channel's kernel status message when the status is 'idle'. It indicates the time at which kernel finished processing the associated request
    """


class Error(BaseModel):
    """
    Output of an error that occurred during code cell execution.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    output_type: Literal["error"]
    """
    Type of cell output.
    """
    ename: str
    """
    The name of the error.
    """
    evalue: str
    """
    The value, or message, of the error.
    """
    traceback: list[str]
    """
    The error's traceback, represented as an array of strings.
    """


class UnrecognizedOutput(BaseModel):
    """
    Unrecognized output from a future minor-revision to the notebook format.
    """

    model_config = ConfigDict(
        extra="allow",
    )
    output_type: Any
    """
    Type of cell output.
    """


class Misc(RootModel[Any]):
    root: Any


class OutputMetadata(BaseModel):
    """
    Cell output metadata.
    """

    model_config = ConfigDict(
        extra="allow",
    )


class Metadata1(BaseModel):
    """
    Cell-level metadata.
    """

    model_config = ConfigDict(
        extra="allow",
    )
    format: str | None = None
    """
    Raw cell metadata format for nbconvert.
    """
    jupyter: dict[str, Any] | None = None
    """
    Official Jupyter Metadata for Raw Cells
    """
    name: Annotated[str | None, Field(pattern="^.+$")] = None
    """
    The cell's name. If present, must be a non-empty string. Cell names are expected to be unique across all the cells in a given notebook. This criterion cannot be checked by the json schema and must be established by an additional check.
    """
    tags: set[str] | None = None
    """
    The cell's tags. Tags must be unique, and must not contain commas.
    """


class Metadata2(BaseModel):
    """
    Cell-level metadata.
    """

    model_config = ConfigDict(
        extra="allow",
    )
    name: Annotated[str | None, Field(pattern="^.+$")] = None
    """
    The cell's name. If present, must be a non-empty string. Cell names are expected to be unique across all the cells in a given notebook. This criterion cannot be checked by the json schema and must be established by an additional check.
    """
    tags: set[str] | None = None
    """
    The cell's tags. Tags must be unique, and must not contain commas.
    """
    jupyter: dict[str, Any] | None = None
    """
    Official Jupyter Metadata for Markdown Cells
    """


class Metadata3(BaseModel):
    """
    Cell-level metadata.
    """

    model_config = ConfigDict(
        extra="allow",
    )
    jupyter: dict[str, Any] | None = None
    """
    Official Jupyter Metadata for Code Cells
    """
    execution: Execution | None = None
    """
    Execution time for the code in the cell. This tracks time at which messages are received from iopub or shell channels
    """
    collapsed: bool | None = None
    """
    Whether the cell's output is collapsed/expanded.
    """
    scrolled: Literal[True, False, "auto"] | None = None
    """
    Whether the cell's output is scrolled, unscrolled, or autoscrolled.
    """
    name: Annotated[str | None, Field(pattern="^.+$")] = None
    """
    The cell's name. If present, must be a non-empty string. Cell names are expected to be unique across all the cells in a given notebook. This criterion cannot be checked by the json schema and must be established by an additional check.
    """
    tags: set[str] | None = None
    """
    The cell's tags. Tags must be unique, and must not contain commas.
    """


class Metadata4(BaseModel):
    """
    Cell-level metadata.
    """

    model_config = ConfigDict(
        extra="allow",
    )
    name: Annotated[str | None, Field(pattern="^.+$")] = None
    """
    The cell's name. If present, must be a non-empty string. Cell names are expected to be unique across all the cells in a given notebook. This criterion cannot be checked by the json schema and must be established by an additional check.
    """
    tags: set[str] | None = None
    """
    The cell's tags. Tags must be unique, and must not contain commas.
    """


class UnrecognizedCell(BaseModel):
    """
    Unrecognized cell from a future minor-revision to the notebook format.
    """

    model_config = ConfigDict(
        extra="allow",
    )
    cell_type: Any
    """
    String identifying the type of cell.
    """
    metadata: Metadata4
    """
    Cell-level metadata.
    """


class ExecuteResult(BaseModel):
    """
    Result of executing a code cell.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    output_type: Literal["execute_result"]
    """
    Type of cell output.
    """
    execution_count: Annotated[int | None, Field(ge=0)] = None
    """
    A result's prompt number.
    """
    data: dict[str, Any]
    """
    A mime-type keyed dictionary of data
    """
    metadata: OutputMetadata


class DisplayData(BaseModel):
    """
    Data displayed as a result of code cell execution.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    output_type: Literal["display_data"]
    """
    Type of cell output.
    """
    data: dict[str, Any]
    """
    A mime-type keyed dictionary of data
    """
    metadata: OutputMetadata


class Stream(BaseModel):
    """
    Stream output from a code cell.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    output_type: Literal["stream"]
    """
    Type of cell output.
    """
    name: str
    """
    The name of the stream (stdout, stderr).
    """
    text: str | list[str]
    """
    The stream's text output, represented as an array of strings.
    """


class RawCell(BaseModel):
    """
    Notebook raw nbconvert cell.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    id: Annotated[str, Field(max_length=64, min_length=1, pattern="^[a-zA-Z0-9-_]+$")]
    """
    A string field representing the identifier of this particular cell.
    """
    cell_type: Literal["raw"]
    """
    String identifying the type of cell.
    """
    metadata: Metadata1
    """
    Cell-level metadata.
    """
    attachments: dict[str, dict[str, Any]] | None = None
    """
    Media attachments (e.g. inline images), stored as mimebundle keyed by filename.
    """
    source: str | list[str]
    """
    Contents of the cell, represented as an array of lines.
    """


class MarkdownCell(BaseModel):
    """
    Notebook markdown cell.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    id: Annotated[str, Field(max_length=64, min_length=1, pattern="^[a-zA-Z0-9-_]+$")]
    """
    A string field representing the identifier of this particular cell.
    """
    cell_type: Literal["markdown"]
    """
    String identifying the type of cell.
    """
    metadata: Metadata2
    """
    Cell-level metadata.
    """
    attachments: dict[str, dict[str, Any]] | None = None
    """
    Media attachments (e.g. inline images), stored as mimebundle keyed by filename.
    """
    source: str | list[str]
    """
    Contents of the cell, represented as an array of lines.
    """


class CodeCell(BaseModel):
    """
    Notebook code cell.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    id: Annotated[str, Field(max_length=64, min_length=1, pattern="^[a-zA-Z0-9-_]+$")]
    """
    A string field representing the identifier of this particular cell.
    """
    cell_type: Literal["code"]
    """
    String identifying the type of cell.
    """
    metadata: Metadata3
    """
    Cell-level metadata.
    """
    source: str | list[str]
    """
    Contents of the cell, represented as an array of lines.
    """
    outputs: list[ExecuteResult | DisplayData | Stream | Error]
    """
    Execution, display, or stream outputs.
    """
    execution_count: Annotated[int | None, Field(ge=0)] = None
    """
    The code cell's prompt number. Will be null if the cell has not been run.
    """


class JupyterNotebook(BaseModel):
    """
    Jupyter Notebook v4.5 JSON schema.
    """

    model_config = ConfigDict(
        extra="forbid",
    )
    metadata: Metadata
    """
    Notebook root-level metadata.
    """
    nbformat_minor: Annotated[int, Field(ge=5)]
    """
    Notebook format (minor number). Incremented for backward compatible changes to the notebook format.
    """
    nbformat: Annotated[int, Field(ge=4, le=4)]
    """
    Notebook format (major number). Incremented between backwards incompatible changes to the notebook format.
    """
    cells: list[RawCell | MarkdownCell | CodeCell]
    """
    Array of cells of the current notebook.
    """
