"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from openrouter.types import BaseModel, UnrecognizedStr
from openrouter.utils import get_discriminator, validate_open_enum
import pydantic
from pydantic import Discriminator, Tag
from pydantic.functional_validators import PlainValidator
from typing import Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypeAliasType, TypedDict


TypeCustom = Literal["custom",]


FormatTypeGrammar = Literal["grammar",]


Syntax = Union[
    Literal[
        "lark",
        "regex",
    ],
    UnrecognizedStr,
]


class FormatGrammarTypedDict(TypedDict):
    type: FormatTypeGrammar
    definition: str
    syntax: Syntax


class FormatGrammar(BaseModel):
    type: FormatTypeGrammar

    definition: str

    syntax: Annotated[Syntax, PlainValidator(validate_open_enum(False))]


FormatTypeText = Literal["text",]


class FormatTextTypedDict(TypedDict):
    type: FormatTypeText


class FormatText(BaseModel):
    type: FormatTypeText


FormatTypedDict = TypeAliasType(
    "FormatTypedDict", Union[FormatTextTypedDict, FormatGrammarTypedDict]
)


Format = Annotated[
    Union[Annotated[FormatText, Tag("text")], Annotated[FormatGrammar, Tag("grammar")]],
    Discriminator(lambda m: get_discriminator(m, "type", "type")),
]


class CustomToolTypedDict(TypedDict):
    r"""Custom tool configuration"""

    type: TypeCustom
    name: str
    description: NotRequired[str]
    format_: NotRequired[FormatTypedDict]


class CustomTool(BaseModel):
    r"""Custom tool configuration"""

    type: TypeCustom

    name: str

    description: Optional[str] = None

    format_: Annotated[Optional[Format], pydantic.Field(alias="format")] = None
