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

import datetime as dt
import typing

import pydantic

from ......core.datetime_utils import serialize_datetime
from ......core.pydantic_utilities import deep_union_pydantic_dicts
from .....commons.types.invoice_id import InvoiceId
from .....commons.types.organization_id import OrganizationId
from .....commons.types.patient_external_id import PatientExternalId
from .....financials.types.allocation import Allocation
from .....financials.types.patient_transaction_source import PatientTransactionSource
from .....financials.types.refund_reason import RefundReason
from .patient_refund_id import PatientRefundId


class PatientRefund(pydantic.BaseModel):
    patient_refund_id: PatientRefundId
    organization_id: OrganizationId
    source_internal_id: typing.Optional[str] = None
    refund_source: PatientTransactionSource
    amount_cents: int
    patient_external_id: PatientExternalId
    refund_timestamp: typing.Optional[dt.datetime] = None
    refund_note: typing.Optional[str] = None
    allocations: typing.List[Allocation]
    invoice: typing.Optional[InvoiceId] = None
    refund_reason: typing.Optional[RefundReason] = None

    def json(self, **kwargs: typing.Any) -> str:
        kwargs_with_defaults: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        return super().json(**kwargs_with_defaults)

    def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
        kwargs_with_defaults_exclude_unset: typing.Any = {"by_alias": True, "exclude_unset": True, **kwargs}
        kwargs_with_defaults_exclude_none: typing.Any = {"by_alias": True, "exclude_none": True, **kwargs}

        return deep_union_pydantic_dicts(
            super().dict(**kwargs_with_defaults_exclude_unset), super().dict(**kwargs_with_defaults_exclude_none)
        )

    class Config:
        frozen = True
        smart_union = True
        extra = pydantic.Extra.forbid
        json_encoders = {dt.datetime: serialize_datetime}
