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

from __future__ import annotations
from datetime import datetime
from decimal import Decimal
from paygentic_sdk.types import (
    BaseModel,
    Nullable,
    OptionalNullable,
    UNSET,
    UNSET_SENTINEL,
    UnrecognizedStr,
)
from paygentic_sdk.utils import serialize_decimal, validate_decimal
import pydantic
from pydantic import model_serializer
from pydantic.functional_serializers import PlainSerializer
from pydantic.functional_validators import BeforeValidator
from typing import Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


DisputeObject = Literal["dispute",]


DisputeStatus = Union[
    Literal[
        "pending",
        "accepted",
        "declined",
    ],
    UnrecognizedStr,
]
r"""Current status of the dispute"""


class DisputeTypedDict(TypedDict):
    id: str
    r"""Unique identifier for a dispute"""
    created_at: datetime
    customer_id: str
    r"""Customer who filed the dispute"""
    customer_message: str
    r"""Customer's reason for the dispute"""
    disputed_amount: Decimal
    r"""Disputed charge amount in decimal dollar format. Sample values: '2.50' equals $2.50 disputed, '15.00' equals $15.00 disputed, '0.50' equals $0.50 disputed"""
    merchant_id: str
    r"""Unique identifier for an organization"""
    status: DisputeStatus
    r"""Current status of the dispute"""
    updated_at: datetime
    usage_event_id: str
    r"""The usage event being disputed"""
    object: NotRequired[DisputeObject]
    merchant_message: NotRequired[Nullable[str]]
    r"""Merchant's response to the dispute"""
    resolved_at: NotRequired[Nullable[datetime]]
    r"""When the dispute was resolved"""


class Dispute(BaseModel):
    id: str
    r"""Unique identifier for a dispute"""

    created_at: Annotated[datetime, pydantic.Field(alias="createdAt")]

    customer_id: Annotated[str, pydantic.Field(alias="customerId")]
    r"""Customer who filed the dispute"""

    customer_message: Annotated[str, pydantic.Field(alias="customerMessage")]
    r"""Customer's reason for the dispute"""

    disputed_amount: Annotated[
        Annotated[
            Decimal,
            BeforeValidator(validate_decimal),
            PlainSerializer(serialize_decimal(True)),
        ],
        pydantic.Field(alias="disputedAmount"),
    ]
    r"""Disputed charge amount in decimal dollar format. Sample values: '2.50' equals $2.50 disputed, '15.00' equals $15.00 disputed, '0.50' equals $0.50 disputed"""

    merchant_id: Annotated[str, pydantic.Field(alias="merchantId")]
    r"""Unique identifier for an organization"""

    status: DisputeStatus
    r"""Current status of the dispute"""

    updated_at: Annotated[datetime, pydantic.Field(alias="updatedAt")]

    usage_event_id: Annotated[str, pydantic.Field(alias="usageEventId")]
    r"""The usage event being disputed"""

    object: Optional[DisputeObject] = "dispute"

    merchant_message: Annotated[
        OptionalNullable[str], pydantic.Field(alias="merchantMessage")
    ] = UNSET
    r"""Merchant's response to the dispute"""

    resolved_at: Annotated[
        OptionalNullable[datetime], pydantic.Field(alias="resolvedAt")
    ] = UNSET
    r"""When the dispute was resolved"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["object", "merchantMessage", "resolvedAt"])
        nullable_fields = set(["merchantMessage", "resolvedAt"])
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k)
            is_nullable_and_explicitly_set = (
                k in nullable_fields
                and (self.__pydantic_fields_set__.intersection({n}))  # pylint: disable=no-member
            )

            if val != UNSET_SENTINEL:
                if (
                    val is not None
                    or k not in optional_fields
                    or is_nullable_and_explicitly_set
                ):
                    m[k] = val

        return m


try:
    Dispute.model_rebuild()
except NameError:
    pass
