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

from ..core.unchecked_base_model import UncheckedBaseModel
from .search_orders_sort_field import SearchOrdersSortField
import pydantic
import typing
from .sort_order import SortOrder
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class SearchOrdersSort(UncheckedBaseModel):
    """
    Sorting criteria for a `SearchOrders` request. Results can only be sorted
    by a timestamp field.
    """

    sort_field: SearchOrdersSortField = pydantic.Field()
    """
    The field to sort by.
    
    __Important:__ When using a [DateTimeFilter](entity:SearchOrdersFilter),
    `sort_field` must match the timestamp field that the `DateTimeFilter` uses to
    filter. For example, if you set your `sort_field` to `CLOSED_AT` and you use a
    `DateTimeFilter`, your `DateTimeFilter` must filter for orders by their `CLOSED_AT` date.
    If this field does not match the timestamp field in `DateTimeFilter`,
    `SearchOrders` returns an error.
    
    Default: `CREATED_AT`.
    See [SearchOrdersSortField](#type-searchorderssortfield) for possible values
    """

    sort_order: typing.Optional[SortOrder] = pydantic.Field(default=None)
    """
    The chronological order in which results are returned. Defaults to `DESC`.
    See [SortOrder](#type-sortorder) for possible values
    """

    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
