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

from __future__ import annotations
from .paymentdestinationtype import PaymentDestinationType
from .paymentgatewaytype import PaymentGatewayType
from .paymentmethodtype import PaymentMethodType
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoCreatePaymentRequestTypedDict(TypedDict):
    amount: str
    currency: str
    destination_id: str
    destination_type: PaymentDestinationType
    payment_method_type: PaymentMethodType
    cancel_url: NotRequired[str]
    idempotency_key: NotRequired[str]
    metadata: NotRequired[Dict[str, str]]
    payment_gateway: NotRequired[PaymentGatewayType]
    payment_method_id: NotRequired[str]
    process_payment: NotRequired[bool]
    save_card_and_make_default: NotRequired[bool]
    success_url: NotRequired[str]


class DtoCreatePaymentRequest(BaseModel):
    amount: str

    currency: str

    destination_id: str

    destination_type: PaymentDestinationType

    payment_method_type: PaymentMethodType

    cancel_url: Optional[str] = None

    idempotency_key: Optional[str] = None

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

    payment_gateway: Optional[PaymentGatewayType] = None

    payment_method_id: Optional[str] = None

    process_payment: Optional[bool] = True

    save_card_and_make_default: Optional[bool] = False

    success_url: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "cancel_url",
                "idempotency_key",
                "metadata",
                "payment_gateway",
                "payment_method_id",
                "process_payment",
                "save_card_and_make_default",
                "success_url",
            ]
        )
        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
