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

from __future__ import annotations
from datetime import datetime
from paygentic_sdk.types import BaseModel, UNSET_SENTINEL, UnrecognizedStr
import pydantic
from pydantic import model_serializer
from typing import Any, Dict, Literal, Optional, Union
from typing_extensions import Annotated, NotRequired, TypedDict


SourceObject = Literal["source",]


ProcessingMode = Union[
    Literal[
        "automatic",
        "manual",
    ],
    UnrecognizedStr,
]


SourceType = Literal["stripe_revenue",]


class SourceTypedDict(TypedDict):
    id: str
    r"""Unique identifier for a source"""
    object: SourceObject
    created_at: datetime
    enabled: bool
    merchant_id: str
    r"""Unique identifier for an organization"""
    name: str
    plan_id: str
    r"""Unique identifier for a plan"""
    processing_mode: ProcessingMode
    type: SourceType
    updated_at: datetime
    config: NotRequired[Dict[str, Any]]
    description: NotRequired[str]
    metadata: NotRequired[Dict[str, Any]]


class Source(BaseModel):
    id: str
    r"""Unique identifier for a source"""

    object: SourceObject

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

    enabled: bool

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

    name: str

    plan_id: Annotated[str, pydantic.Field(alias="planId")]
    r"""Unique identifier for a plan"""

    processing_mode: Annotated[ProcessingMode, pydantic.Field(alias="processingMode")]

    type: SourceType

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

    config: Optional[Dict[str, Any]] = None

    description: Optional[str] = None

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

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(["config", "description", "metadata"])
        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


try:
    Source.model_rebuild()
except NameError:
    pass
