"""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 validate_open_enum
from datetime import date
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 BalanceByTransactionTransactionType(str, Enum, metaclass=utils.OpenEnumMeta):
    r"""Type of the transaction."""

    INVOICE = "invoice"
    CREDIT_NOTE = "credit_note"
    BILL = "bill"
    PAYMENT = "payment"
    BILL_PAYMENT = "bill_payment"


class BalanceByTransactionTypedDict(TypedDict):
    transaction_id: NotRequired[str]
    r"""Unique identifier for the transaction."""
    transaction_date: NotRequired[date]
    r"""Date of the transaction."""
    transaction_type: NotRequired[BalanceByTransactionTransactionType]
    r"""Type of the transaction."""
    due_date: NotRequired[date]
    r"""Due date of the transaction."""
    original_amount: NotRequired[float]
    r"""Original amount of the transaction."""
    outstanding_balance: NotRequired[float]
    r"""Outstanding balance of the transaction."""
    transaction_number: NotRequired[str]
    r"""Transaction number of the transaction."""


class BalanceByTransaction(BaseModel):
    transaction_id: Optional[str] = None
    r"""Unique identifier for the transaction."""

    transaction_date: Optional[date] = None
    r"""Date of the transaction."""

    transaction_type: Annotated[
        Optional[BalanceByTransactionTransactionType],
        PlainValidator(validate_open_enum(False)),
    ] = None
    r"""Type of the transaction."""

    due_date: Optional[date] = None
    r"""Due date of the transaction."""

    original_amount: Optional[float] = None
    r"""Original amount of the transaction."""

    outstanding_balance: Optional[float] = None
    r"""Outstanding balance of the transaction."""

    transaction_number: Optional[str] = None
    r"""Transaction number of the transaction."""

    @field_serializer("transaction_type")
    def serialize_transaction_type(self, value):
        if isinstance(value, str):
            try:
                return models.BalanceByTransactionTransactionType(value)
            except ValueError:
                return value
        return value
