"""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


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


FormatTypeGrammar = Literal["grammar",]


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


class FormatGrammar(BaseModel):
    definition: str

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

    type: FormatTypeGrammar


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")),
]


CustomToolTypeCustom = Literal["custom",]


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

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


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

    name: str

    type: CustomToolTypeCustom

    description: Optional[str] = None

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