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

from __future__ import annotations
from .schedulestatus import ScheduleStatus
from .subscriptionschedulechangetype import SubscriptionScheduleChangeType
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, Optional
from typing_extensions import NotRequired, TypedDict


class ConfigurationTypedDict(TypedDict):
    r"""configuration contains type-specific configuration (e.g., target_plan_id for plan changes)"""


class Configuration(BaseModel):
    r"""configuration contains type-specific configuration (e.g., target_plan_id for plan changes)"""


class ExecutionResultTypedDict(TypedDict):
    r"""execution_result contains type-specific execution result"""


class ExecutionResult(BaseModel):
    r"""execution_result contains type-specific execution result"""


class DtoSubscriptionScheduleResponseTypedDict(TypedDict):
    r"""Full details of a subscription schedule"""

    can_be_cancelled: NotRequired[bool]
    r"""can_be_cancelled indicates if the schedule can be cancelled"""
    cancelled_at: NotRequired[str]
    r"""cancelled_at is when the schedule was cancelled"""
    configuration: NotRequired[ConfigurationTypedDict]
    r"""configuration contains type-specific configuration (e.g., target_plan_id for plan changes)"""
    created_at: NotRequired[str]
    r"""created_at timestamp"""
    days_until_execution: NotRequired[int]
    r"""days_until_execution is the number of days until execution"""
    error_message: NotRequired[str]
    r"""error_message contains the error if execution failed"""
    executed_at: NotRequired[str]
    r"""executed_at is when the schedule was executed"""
    execution_result: NotRequired[ExecutionResultTypedDict]
    r"""execution_result contains type-specific execution result"""
    id: NotRequired[str]
    r"""id of the schedule"""
    metadata: NotRequired[Dict[str, str]]
    r"""metadata from the schedule"""
    schedule_type: NotRequired[SubscriptionScheduleChangeType]
    scheduled_at: NotRequired[str]
    r"""scheduled_at is when the schedule will execute"""
    status: NotRequired[ScheduleStatus]
    subscription_id: NotRequired[str]
    r"""subscription_id is the ID of the subscription"""
    updated_at: NotRequired[str]
    r"""updated_at timestamp"""


class DtoSubscriptionScheduleResponse(BaseModel):
    r"""Full details of a subscription schedule"""

    can_be_cancelled: Optional[bool] = None
    r"""can_be_cancelled indicates if the schedule can be cancelled"""

    cancelled_at: Optional[str] = None
    r"""cancelled_at is when the schedule was cancelled"""

    configuration: Optional[Configuration] = None
    r"""configuration contains type-specific configuration (e.g., target_plan_id for plan changes)"""

    created_at: Optional[str] = None
    r"""created_at timestamp"""

    days_until_execution: Optional[int] = None
    r"""days_until_execution is the number of days until execution"""

    error_message: Optional[str] = None
    r"""error_message contains the error if execution failed"""

    executed_at: Optional[str] = None
    r"""executed_at is when the schedule was executed"""

    execution_result: Optional[ExecutionResult] = None
    r"""execution_result contains type-specific execution result"""

    id: Optional[str] = None
    r"""id of the schedule"""

    metadata: Optional[Dict[str, str]] = None
    r"""metadata from the schedule"""

    schedule_type: Optional[SubscriptionScheduleChangeType] = None

    scheduled_at: Optional[str] = None
    r"""scheduled_at is when the schedule will execute"""

    status: Optional[ScheduleStatus] = None

    subscription_id: Optional[str] = None
    r"""subscription_id is the ID of the subscription"""

    updated_at: Optional[str] = None
    r"""updated_at timestamp"""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "can_be_cancelled",
                "cancelled_at",
                "configuration",
                "created_at",
                "days_until_execution",
                "error_message",
                "executed_at",
                "execution_result",
                "id",
                "metadata",
                "schedule_type",
                "scheduled_at",
                "status",
                "subscription_id",
                "updated_at",
            ]
        )
        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
