# This file was auto-generated by Fern from our API Definition.

from ..core.unchecked_base_model import UncheckedBaseModel
import typing
import pydantic
from .subscription_cadence import SubscriptionCadence
from .money import Money
from .subscription_pricing import SubscriptionPricing
from ..core.pydantic_utilities import IS_PYDANTIC_V2


class SubscriptionPhase(UncheckedBaseModel):
    """
    Describes a phase in a subscription plan variation. For more information, see [Subscription Plans and Variations](https://developer.squareup.com/docs/subscriptions-api/plans-and-variations).
    """

    uid: typing.Optional[str] = pydantic.Field(default=None)
    """
    The Square-assigned ID of the subscription phase. This field cannot be changed after a `SubscriptionPhase` is created.
    """

    cadence: SubscriptionCadence = pydantic.Field()
    """
    The billing cadence of the phase. For example, weekly or monthly. This field cannot be changed after a `SubscriptionPhase` is created.
    See [SubscriptionCadence](#type-subscriptioncadence) for possible values
    """

    periods: typing.Optional[int] = pydantic.Field(default=None)
    """
    The number of `cadence`s the phase lasts. If not set, the phase never ends. Only the last phase can be indefinite. This field cannot be changed after a `SubscriptionPhase` is created.
    """

    recurring_price_money: typing.Optional[Money] = pydantic.Field(default=None)
    """
    The amount to bill for each `cadence`. Failure to specify this field results in a `MISSING_REQUIRED_PARAMETER` error at runtime.
    """

    ordinal: typing.Optional[int] = pydantic.Field(default=None)
    """
    The position this phase appears in the sequence of phases defined for the plan, indexed from 0. This field cannot be changed after a `SubscriptionPhase` is created.
    """

    pricing: typing.Optional[SubscriptionPricing] = pydantic.Field(default=None)
    """
    The subscription pricing.
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
