"""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
from pydantic import field_serializer
from pydantic.functional_validators import PlainValidator
from typing import Optional
from typing_extensions import Annotated, NotRequired, TypedDict


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

    CASH = "cash"
    ACCRUAL = "accrual"


class ProfitAndLossFilterTypedDict(TypedDict):
    customer_id: NotRequired[str]
    r"""Filter by customer id"""
    start_date: NotRequired[str]
    r"""Filter by start date. If start date is given, end date is required."""
    end_date: NotRequired[str]
    r"""Filter by end date. If end date is given, start date is required."""
    location_id: NotRequired[str]
    r"""Filter by location id"""
    accounting_method: NotRequired[ProfitAndLossFilterAccountingMethod]
    r"""The accounting method used for the report: cash or accrual."""


class ProfitAndLossFilter(BaseModel):
    customer_id: Annotated[Optional[str], FieldMetadata(query=True)] = None
    r"""Filter by customer id"""

    start_date: Annotated[Optional[str], FieldMetadata(query=True)] = None
    r"""Filter by start date. If start date is given, end date is required."""

    end_date: Annotated[Optional[str], FieldMetadata(query=True)] = None
    r"""Filter by end date. If end date is given, start date is required."""

    location_id: Annotated[Optional[str], FieldMetadata(query=True)] = None
    r"""Filter by location id"""

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

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