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

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


CreateSourceProcessingMode = Literal[
    "automatic",
    "manual",
]
r"""How events are processed - automatic (immediate) or manual (requires approval)"""


CreateSourceType = Literal["stripe_revenue",]
r"""The type of source. Currently only 'stripe_revenue' is supported."""


class CreateSourceRequestTypedDict(TypedDict):
    name: str
    r"""Display label for the external data source. Sample values: 'Stripe Revenue Integration', 'LLM Usage Tracker', 'Data Processing Monitor', 'ML Compute Usage Source'"""
    plan_id: str
    r"""Unique identifier for a plan"""
    type: CreateSourceType
    r"""The type of source. Currently only 'stripe_revenue' is supported."""
    config: NotRequired[Dict[str, Any]]
    r"""Configuration specific to the source type. For stripe_revenue, must include ampersandProjectId."""
    description: NotRequired[str]
    r"""Optional explanation of the source's purpose. Sample values: 'Automated usage tracking from Stripe revenue data', 'Language model token consumption monitoring', 'Data warehouse query tracking', 'Machine learning inference usage collection'"""
    enabled: NotRequired[bool]
    r"""Whether the source is enabled"""
    metadata: NotRequired[Dict[str, Any]]
    r"""Metadata for the source. For stripe_revenue, must include billableMetricMapping with revenue (billable metric ID)."""
    processing_mode: NotRequired[CreateSourceProcessingMode]
    r"""How events are processed - automatic (immediate) or manual (requires approval)"""


class CreateSourceRequest(BaseModel):
    name: str
    r"""Display label for the external data source. Sample values: 'Stripe Revenue Integration', 'LLM Usage Tracker', 'Data Processing Monitor', 'ML Compute Usage Source'"""

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

    type: CreateSourceType
    r"""The type of source. Currently only 'stripe_revenue' is supported."""

    config: Optional[Dict[str, Any]] = None
    r"""Configuration specific to the source type. For stripe_revenue, must include ampersandProjectId."""

    description: Optional[str] = None
    r"""Optional explanation of the source's purpose. Sample values: 'Automated usage tracking from Stripe revenue data', 'Language model token consumption monitoring', 'Data warehouse query tracking', 'Machine learning inference usage collection'"""

    enabled: Optional[bool] = True
    r"""Whether the source is enabled"""

    metadata: Optional[Dict[str, Any]] = None
    r"""Metadata for the source. For stripe_revenue, must include billableMetricMapping with revenue (billable metric ID)."""

    processing_mode: Annotated[
        Optional[CreateSourceProcessingMode], pydantic.Field(alias="processingMode")
    ] = "automatic"
    r"""How events are processed - automatic (immediate) or manual (requires approval)"""

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


try:
    CreateSourceRequest.model_rebuild()
except NameError:
    pass
