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

from __future__ import annotations
from .matchtype import MatchType
from pydantic import model_serializer
from syllable_sdk.types import BaseModel, UNSET_SENTINEL
from typing import List, Optional
from typing_extensions import NotRequired, TypedDict


class PronunciationOverrideTypedDict(TypedDict):
    r"""A single text replacement rule."""

    text: str
    replacement: str
    languages: NotRequired[List[str]]
    provider: NotRequired[str]
    voice: NotRequired[str]
    match_type: NotRequired[MatchType]
    r"""Matching strategy for override text."""
    match_options: NotRequired[List[str]]
    enabled: NotRequired[bool]
    notes: NotRequired[str]


class PronunciationOverride(BaseModel):
    r"""A single text replacement rule."""

    text: str

    replacement: str

    languages: Optional[List[str]] = None

    provider: Optional[str] = ""

    voice: Optional[str] = ""

    match_type: Optional[MatchType] = None
    r"""Matching strategy for override text."""

    match_options: Optional[List[str]] = None

    enabled: Optional[bool] = True

    notes: Optional[str] = ""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "languages",
                "provider",
                "voice",
                "match_type",
                "match_options",
                "enabled",
                "notes",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
