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

import typing

import pydantic
import typing_extensions
from ..core.pydantic_utilities import IS_PYDANTIC_V2
from ..core.serialization import FieldMetadata
from ..core.unchecked_base_model import UncheckedBaseModel


class CacheDirective(UncheckedBaseModel):
    """
    Client-controlled caching directives for atom generation.

    Modes:
    - Default (read=True, write=True): Serve cache if fresh, else generate
    - No-cache (read=False, write=False): Generate, don't store (ephemeral)
    - Force refresh (read=False, write=True): Generate fresh, cache result
    - SWR (read=True, write=True, revalidate=True): Serve cache, then stream refresh
    """

    read: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Read from cache if available and fresh
    """

    write: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Write generated atoms to cache
    """

    max_stale: typing_extensions.Annotated[typing.Optional[int], FieldMetadata(alias="maxStale")] = pydantic.Field(
        default=None
    )
    """
    Maximum staleness in seconds — how old cached data the client will accept (default: 86400 = 24h)
    """

    revalidate: typing.Optional[bool] = pydantic.Field(default=None)
    """
    Serve cached then stream refresh (SWR mode)
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
