# This file was auto-generated by Fern from our API Definition.

import datetime as dt
import typing

from ..core.datetime_utils import serialize_datetime
from .method_enum import MethodEnum
from .response_data import ResponseData

try:
    import pydantic.v1 as pydantic  # type: ignore
except ImportError:
    import pydantic  # type: ignore


class DynamicData(pydantic.BaseModel):
    """
    from blandai import DynamicData, ResponseData

    DynamicData(
        url="https://api.coindesk.com/v1/bpi/currentprice.json",
        response_data=[
            ResponseData(
                name="BTC Price USD",
                data="bpi.USD.rate",
                context="Current BTC Price: $BTC Price USD USD",
            ),
            ResponseData(
                name="BTC Price EUR",
                data="bpi.EUR.rate",
                context="In Euros: BTC Price USD EUR",
            ),
        ],
    )
    """

    url: str = pydantic.Field()
    """
    The URL of the external API to fetch data from.
    """

    response_data: typing.List[ResponseData] = pydantic.Field()
    """
    An array of objects describing how to parse and use the data fetched from the API.
    """

    method: typing.Optional[MethodEnum] = pydantic.Field(default=None)
    """
    Default value is `GET`.
    """

    cache: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Whether to fetch the data once at the beginning of the call, or to re-check continuously for data that might change mid-call. Default value is `true`.
    """

    headers: typing.Optional[typing.Dict[str, str]] = pydantic.Field(default=None)
    """
    An object of headers to send with the request.
    """

    body: typing.Optional[str] = pydantic.Field(default=None)
    """
    The body of the request.
    
    The following variables can be injected into the dynamic request body with double curly braces:
    
    - `from` (Ex. `+12223334444`)
    - `to`
    - `short_from` (Ex. `2223334444`)
    - `short_to`
    - `call_id`
    
    These string values will be replaced in each `dynamic_data[].body` where they're used by system values in each request.
    """

    def json(self, **kwargs: typing.Any) -> str:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().json(**kwargs_with_defaults)

    def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().dict(**kwargs_with_defaults)

    class Config:
        frozen = True
        smart_union = True
        json_encoders = {dt.datetime: serialize_datetime}
