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

from __future__ import annotations
from .dto_customerresponse import DtoCustomerResponse, DtoCustomerResponseTypedDict
from .dto_userresponse import DtoUserResponse, DtoUserResponseTypedDict
from .dto_walletresponse import DtoWalletResponse, DtoWalletResponseTypedDict
from .status import Status
from .transactionreason import TransactionReason
from .transactionstatus import TransactionStatus
from .transactiontype import TransactionType
from .wallettxreferencetype import WalletTxReferenceType
from flexprice_py.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class DtoWalletTransactionResponseTypedDict(TypedDict):
    amount: NotRequired[str]
    conversion_rate: NotRequired[str]
    r"""conversion_rate is the conversion rate for the transaction to the currency"""
    created_at: NotRequired[str]
    created_by: NotRequired[str]
    created_by_user: NotRequired[DtoUserResponseTypedDict]
    credit_amount: NotRequired[str]
    credit_balance_after: NotRequired[str]
    credit_balance_before: NotRequired[str]
    credits_available: NotRequired[str]
    currency: NotRequired[str]
    customer: NotRequired[DtoCustomerResponseTypedDict]
    r"""Customer response object containing all customer information"""
    customer_id: NotRequired[str]
    description: NotRequired[str]
    environment_id: NotRequired[str]
    expiry_date: NotRequired[str]
    id: NotRequired[str]
    idempotency_key: NotRequired[str]
    metadata: NotRequired[Dict[str, str]]
    priority: NotRequired[int]
    reference_id: NotRequired[str]
    reference_type: NotRequired[WalletTxReferenceType]
    status: NotRequired[Status]
    tenant_id: NotRequired[str]
    topup_conversion_rate: NotRequired[str]
    r"""topup_conversion_rate is the conversion rate for the topup to the currency"""
    transaction_reason: NotRequired[TransactionReason]
    transaction_status: NotRequired[TransactionStatus]
    type: NotRequired[TransactionType]
    updated_at: NotRequired[str]
    updated_by: NotRequired[str]
    wallet: NotRequired[DtoWalletResponseTypedDict]
    wallet_id: NotRequired[str]


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

    conversion_rate: Optional[str] = None
    r"""conversion_rate is the conversion rate for the transaction to the currency"""

    created_at: Optional[str] = None

    created_by: Optional[str] = None

    created_by_user: Optional[DtoUserResponse] = None

    credit_amount: Optional[str] = None

    credit_balance_after: Optional[str] = None

    credit_balance_before: Optional[str] = None

    credits_available: Optional[str] = None

    currency: Optional[str] = None

    customer: Optional[DtoCustomerResponse] = None
    r"""Customer response object containing all customer information"""

    customer_id: Optional[str] = None

    description: Optional[str] = None

    environment_id: Optional[str] = None

    expiry_date: Optional[str] = None

    id: Optional[str] = None

    idempotency_key: Optional[str] = None

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

    priority: Optional[int] = None

    reference_id: Optional[str] = None

    reference_type: Optional[WalletTxReferenceType] = None

    status: Optional[Status] = None

    tenant_id: Optional[str] = None

    topup_conversion_rate: Optional[str] = None
    r"""topup_conversion_rate is the conversion rate for the topup to the currency"""

    transaction_reason: Optional[TransactionReason] = None

    transaction_status: Optional[TransactionStatus] = None

    type: Optional[TransactionType] = None

    updated_at: Optional[str] = None

    updated_by: Optional[str] = None

    wallet: Optional[DtoWalletResponse] = None

    wallet_id: Optional[str] = None

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "amount",
                "conversion_rate",
                "created_at",
                "created_by",
                "created_by_user",
                "credit_amount",
                "credit_balance_after",
                "credit_balance_before",
                "credits_available",
                "currency",
                "customer",
                "customer_id",
                "description",
                "environment_id",
                "expiry_date",
                "id",
                "idempotency_key",
                "metadata",
                "priority",
                "reference_id",
                "reference_type",
                "status",
                "tenant_id",
                "topup_conversion_rate",
                "transaction_reason",
                "transaction_status",
                "type",
                "updated_at",
                "updated_by",
                "wallet",
                "wallet_id",
            ]
        )
        serialized = handler(self)
        m = {}

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

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

        return m
