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

from __future__ import annotations
from .dto_overridelineitemrequest import (
    DtoOverrideLineItemRequest,
    DtoOverrideLineItemRequestTypedDict,
)
from flexprice.types import BaseModel, UNSET_SENTINEL
from pydantic import model_serializer
from typing import Dict, List, Optional
from typing_extensions import NotRequired, TypedDict


class DtoSubscriptionPhaseCreateRequestTypedDict(TypedDict):
    start_date: str
    coupons: NotRequired[List[str]]
    r"""Coupons represents subscription-level coupons to be applied to this phase"""
    end_date: NotRequired[str]
    line_item_coupons: NotRequired[Dict[str, List[str]]]
    r"""LineItemCoupons represents line item-level coupons (map of line_item_id to coupon IDs)"""
    metadata: NotRequired[Dict[str, str]]
    override_line_items: NotRequired[List[DtoOverrideLineItemRequestTypedDict]]
    r"""OverrideLineItems allows customizing specific prices for this phase
    If not provided, phase will use the same line items as the subscription (plan prices)
    """


class DtoSubscriptionPhaseCreateRequest(BaseModel):
    start_date: str

    coupons: Optional[List[str]] = None
    r"""Coupons represents subscription-level coupons to be applied to this phase"""

    end_date: Optional[str] = None

    line_item_coupons: Optional[Dict[str, List[str]]] = None
    r"""LineItemCoupons represents line item-level coupons (map of line_item_id to coupon IDs)"""

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

    override_line_items: Optional[List[DtoOverrideLineItemRequest]] = None
    r"""OverrideLineItems allows customizing specific prices for this phase
    If not provided, phase will use the same line items as the subscription (plan prices)
    """

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