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

from __future__ import annotations
from .dto_paymentattemptresponse import (
    DtoPaymentAttemptResponse,
    DtoPaymentAttemptResponseTypedDict,
)
from .paymentdestinationtype import PaymentDestinationType
from .paymentmethodtype import PaymentMethodType
from .paymentstatus import PaymentStatus
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoPaymentResponseTypedDict(TypedDict):
    amount: NotRequired[str]
    attempts: NotRequired[List[DtoPaymentAttemptResponseTypedDict]]
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    currency: NotRequired[str]
    destination_id: NotRequired[str]
    destination_type: NotRequired[PaymentDestinationType]
    error_message: NotRequired[str]
    failed_at: NotRequired[str]
    gateway_metadata: NotRequired[Dict[str, str]]
    gateway_payment_id: NotRequired[str]
    gateway_tracking_id: NotRequired[str]
    id: NotRequired[str]
    idempotency_key: NotRequired[str]
    invoice_number: NotRequired[str]
    metadata: NotRequired[Dict[str, str]]
    payment_gateway: NotRequired[str]
    payment_method_id: NotRequired[str]
    payment_method_type: NotRequired[PaymentMethodType]
    payment_status: NotRequired[PaymentStatus]
    payment_url: NotRequired[str]
    refunded_at: NotRequired[str]
    save_card_and_make_default: NotRequired[bool]
    succeeded_at: NotRequired[str]
    tenant_id: NotRequired[str]
    track_attempts: NotRequired[bool]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]


class DtoPaymentResponse(BaseModel):
    amount: Optional[str] = None

    attempts: Optional[List[DtoPaymentAttemptResponse]] = None

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    currency: Optional[str] = None

    destination_id: Optional[str] = None

    destination_type: Optional[PaymentDestinationType] = None

    error_message: Optional[str] = None

    failed_at: Optional[str] = None

    gateway_metadata: Optional[Dict[str, str]] = None

    gateway_payment_id: Optional[str] = None

    gateway_tracking_id: Optional[str] = None

    id: Optional[str] = None

    idempotency_key: Optional[str] = None

    invoice_number: Optional[str] = None

    metadata: Optional[Dict[str, str]] = None

    payment_gateway: Optional[str] = None

    payment_method_id: Optional[str] = None

    payment_method_type: Optional[PaymentMethodType] = None

    payment_status: Optional[PaymentStatus] = None

    payment_url: Optional[str] = None

    refunded_at: Optional[str] = None

    save_card_and_make_default: Optional[bool] = None

    succeeded_at: Optional[str] = None

    tenant_id: Optional[str] = None

    track_attempts: Optional[bool] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount",
                "attempts",
                "created_at",
                "created_by",
                "currency",
                "destination_id",
                "destination_type",
                "error_message",
                "failed_at",
                "gateway_metadata",
                "gateway_payment_id",
                "gateway_tracking_id",
                "id",
                "idempotency_key",
                "invoice_number",
                "metadata",
                "payment_gateway",
                "payment_method_id",
                "payment_method_type",
                "payment_status",
                "payment_url",
                "refunded_at",
                "save_card_and_make_default",
                "succeeded_at",
                "tenant_id",
                "track_attempts",
                "updated_at",
                "updated_by",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

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

        return m
