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

from __future__ import annotations
from apideck_unify import models, utils
from apideck_unify.types import BaseModel
from apideck_unify.utils import FieldMetadata, validate_open_enum
from enum import Enum
import pydantic
from pydantic import field_serializer
from pydantic.functional_validators import PlainValidator
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


class PeriodType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The type of period to include in the resource: month, quarter, year."""

    MONTH = "month"
    QUARTER = "quarter"
    YEAR = "year"


class AccountingMethod(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""The accounting method used for the report: cash or accrual."""

    CASH = "cash"
    ACCRUAL = "accrual"


class BalanceSheetFilterTypedDict(TypedDict):
    start_date: NotRequired[str]
    r"""The start date of the period to include in the resource."""
    end_date: NotRequired[str]
    r"""The end date of the period to include in the resource."""
    period_count: NotRequired[int]
    r"""The number of periods to include in the resource."""
    period_type: NotRequired[PeriodType]
    r"""The type of period to include in the resource: month, quarter, year."""
    location_id: NotRequired[str]
    r"""The ID of the location to include in the resource."""
    accounting_method: NotRequired[AccountingMethod]
    r"""The accounting method used for the report: cash or accrual."""


class BalanceSheetFilter(BaseModel):
    start_date: Annotated[
        Optional[str],
        pydantic.Field(
            deprecated="warning: ** DEPRECATED ** - This field is deprecated and may be removed in a future version.."
        ),
        FieldMetadata(query=True),
    ] = None
    r"""The start date of the period to include in the resource."""

    end_date: Annotated[Optional[str], FieldMetadata(query=True)] = None
    r"""The end date of the period to include in the resource."""

    period_count: Annotated[Optional[int], FieldMetadata(query=True)] = None
    r"""The number of periods to include in the resource."""

    period_type: Annotated[
        Annotated[Optional[PeriodType], PlainValidator(validate_open_enum(False))],
        FieldMetadata(query=True),
    ] = None
    r"""The type of period to include in the resource: month, quarter, year."""

    location_id: Annotated[Optional[str], FieldMetadata(query=True)] = None
    r"""The ID of the location to include in the resource."""

    accounting_method: Annotated[
        Annotated[
            Optional[AccountingMethod], PlainValidator(validate_open_enum(False))
        ],
        FieldMetadata(query=True),
    ] = None
    r"""The accounting method used for the report: cash or accrual."""

    @field_serializer("period_type")
    def serialize_period_type(self, value):
        if isinstance(value, str):
            try:
                return models.PeriodType(value)
            except ValueError:
                return value
        return value

    @field_serializer("accounting_method")
    def serialize_accounting_method(self, value):
        if isinstance(value, str):
            try:
                return models.AccountingMethod(value)
            except ValueError:
                return value
        return value
