# -*- coding: utf-8 -*-
# File generated from our OpenAPI spec
from decimal import Decimal
from stripe._stripe_object import StripeObject, UntypedStripeObject
from typing import ClassVar, List, Optional
from typing_extensions import Literal


class IntentAction(StripeObject):
    """
    A Billing Intent Action represents a specific operation within a Billing Intent, such as subscribing to a Pricing Plan,
    modifying a subscription's quantity, or deactivating service. Each action has a specific type and associated details that
    define what change will be made when the Intent is committed.
    """

    OBJECT_NAME: ClassVar[Literal["v2.billing.intent_action"]] = (
        "v2.billing.intent_action"
    )

    class Apply(StripeObject):
        class Discount(StripeObject):
            coupon: Optional[str]
            """
            The ID of the Coupon applied.
            """
            discount: Optional[str]
            """
            The ID of the created Discount.
            """
            promotion_code: Optional[str]
            """
            The ID of the PromotionCode applied.
            """
            type: Literal["coupon", "promotion_code"]
            """
            Type of the discount.
            """

        class EffectiveAt(StripeObject):
            timestamp: Optional[str]
            """
            The timestamp at which the apply action takes effect. Only present if type is timestamp. Only allowed for discount actions.
            """
            type: Literal[
                "current_billing_period_end",
                "current_billing_period_start",
                "next_billing_period_start",
                "on_reserve",
                "timestamp",
            ]
            """
            When the apply action takes effect.
            """

        class InvoiceDiscountRule(StripeObject):
            class PercentOff(StripeObject):
                class MaximumApplications(StripeObject):
                    type: Literal["indefinite"]
                    """
                    The type of maximum applications configuration.
                    """

                maximum_applications: MaximumApplications
                """
                The maximum number of times this discount can be applied for this Billing Cadence.
                """
                percent_off: Decimal
                """
                Percent that is taken off the amount. For example, a percent_off of 50.0 reduces a 100 USD amount to 50 USD.
                """
                _inner_class_types = {
                    "maximum_applications": MaximumApplications,
                }
                _field_encodings = {"percent_off": "decimal_string"}

            applies_to: Literal["cadence"]
            """
            The entity that the discount rule applies to, for example, the Billing Cadence.
            """
            invoice_discount_rule: Optional[str]
            """
            The ID of the created discount rule. This is only present once the Billing Intent is committed and the discount rule is created.
            """
            percent_off: Optional[PercentOff]
            """
            Configuration for percentage off discount.
            """
            type: Literal["percent_off"]
            """
            Type of the discount rule.
            """
            _inner_class_types = {"percent_off": PercentOff}

        class SpendModifierRule(StripeObject):
            class MaxBillingPeriodSpend(StripeObject):
                class Amount(StripeObject):
                    class CustomPricingUnit(StripeObject):
                        id: Optional[str]
                        """
                        The id of the custom pricing unit.
                        """
                        value: str
                        """
                        The value of the custom pricing unit.
                        """

                    custom_pricing_unit: Optional[CustomPricingUnit]
                    """
                    The custom pricing unit amount.
                    """
                    type: Literal["custom_pricing_unit"]
                    """
                    The type of the amount.
                    """
                    _inner_class_types = {
                        "custom_pricing_unit": CustomPricingUnit,
                    }

                class CustomPricingUnitOverageRate(StripeObject):
                    id: str
                    """
                    ID of the custom pricing unit overage rate.
                    """

                amount: Amount
                """
                The maximum amount allowed for the billing period.
                """
                custom_pricing_unit_overage_rate: CustomPricingUnitOverageRate
                """
                The configuration for the overage rate for the custom pricing unit.
                """
                _inner_class_types = {
                    "amount": Amount,
                    "custom_pricing_unit_overage_rate": CustomPricingUnitOverageRate,
                }

            applies_to: Literal["cadence"]
            """
            What the spend modifier applies to.
            """
            id: str
            """
            The ID of the spend modifier.
            """
            max_billing_period_spend: Optional[MaxBillingPeriodSpend]
            """
            Details for max billing period spend modifier. Only present if type is max_billing_period_spend.
            """
            type: Literal["max_billing_period_spend"]
            """
            Type of the spend modifier.
            """
            _inner_class_types = {
                "max_billing_period_spend": MaxBillingPeriodSpend,
            }

        discount: Optional[Discount]
        """
        Details for applying a discount.
        """
        effective_at: Optional[EffectiveAt]
        """
        When the apply action takes effect. If not specified, defaults to on_reserve.
        """
        invoice_discount_rule: Optional[InvoiceDiscountRule]
        """
        Details for applying a discount rule to future invoices.
        """
        spend_modifier_rule: Optional[SpendModifierRule]
        """
        Details for applying a spend modifier rule. Only present if type is spend_modifier_rule.
        """
        type: Literal[
            "discount", "invoice_discount_rule", "spend_modifier_rule"
        ]
        """
        Type of the apply action details.
        """
        _inner_class_types = {
            "discount": Discount,
            "effective_at": EffectiveAt,
            "invoice_discount_rule": InvoiceDiscountRule,
            "spend_modifier_rule": SpendModifierRule,
        }

    class Deactivate(StripeObject):
        class CancellationDetails(StripeObject):
            comment: Optional[str]
            """
            Additional comments about why the user canceled the subscription, if the subscription was canceled explicitly by the user.
            """
            feedback: Optional[
                Literal[
                    "customer_service",
                    "low_quality",
                    "missing_features",
                    "other",
                    "switched_service",
                    "too_complex",
                    "too_expensive",
                    "unused",
                ]
            ]
            """
            The customer submitted reason for why they canceled, if the subscription was canceled explicitly by the user.
            """

        class EffectiveAt(StripeObject):
            timestamp: Optional[str]
            """
            The timestamp at which the deactivate action takes effect. Only present if type is timestamp.
            """
            type: Literal[
                "current_billing_period_end",
                "current_billing_period_start",
                "on_reserve",
                "timestamp",
            ]
            """
            When the deactivate action takes effect.
            """

        class PricingPlanSubscriptionDetails(StripeObject):
            class Overrides(StripeObject):
                class PartialPeriodBehavior(StripeObject):
                    class LicenseFee(StripeObject):
                        credit_proration_behavior: Literal["none", "prorated"]
                        """
                        The proration behavior for the partial servicing period. Defines how we prorate the license fee when the user is deactivating. If not specified, defaults to none.
                        """

                    license_fee: Optional[LicenseFee]
                    """
                    Overrides the behavior for license fee components when the action takes effect during the service period.
                    """
                    type: Literal["license_fee", "recurring_credit_grant"]
                    """
                    The type of behavior to override.
                    """
                    _inner_class_types = {"license_fee": LicenseFee}

                partial_period_behaviors: List[PartialPeriodBehavior]
                """
                Configurations for behaviors when the action takes effect during the service period.
                """
                _inner_class_types = {
                    "partial_period_behaviors": PartialPeriodBehavior,
                }

            overrides: Optional[Overrides]
            """
            Configurations for overriding behaviors related to the subscription.
            """
            pricing_plan_subscription: str
            """
            ID of the Pricing Plan Subscription to deactivate.
            """
            _inner_class_types = {"overrides": Overrides}

        cancellation_details: Optional[CancellationDetails]
        """
        Details about why the cancellation was requested by the user.
        """
        collect_at: Literal["next_billing_date", "on_effective_at"]
        """
        Allows users to override the collect at behavior.
        """
        effective_at: EffectiveAt
        """
        When the deactivate action takes effect. If not specified, the default behavior is on_reserve.
        """
        pricing_plan_subscription_details: Optional[
            PricingPlanSubscriptionDetails
        ]
        """
        Details for deactivating a Pricing Plan Subscription.
        """
        type: Literal[
            "pricing_plan_subscription_details", "v1_subscription_details"
        ]
        """
        Type of the action details.
        """
        _inner_class_types = {
            "cancellation_details": CancellationDetails,
            "effective_at": EffectiveAt,
            "pricing_plan_subscription_details": PricingPlanSubscriptionDetails,
        }

    class Modify(StripeObject):
        class EffectiveAt(StripeObject):
            timestamp: Optional[str]
            """
            The timestamp at which the modify action takes effect. Only present if type is timestamp.
            """
            type: Literal[
                "current_billing_period_start", "on_reserve", "timestamp"
            ]
            """
            When the modify action takes effect.
            """

        class PricingPlanSubscriptionDetails(StripeObject):
            class ComponentConfiguration(StripeObject):
                lookup_key: Optional[str]
                """
                Lookup key for the pricing plan component.
                """
                pricing_plan_component: Optional[str]
                """
                ID of the pricing plan component.
                """
                quantity: Optional[int]
                """
                Quantity of the component to be used.
                """

            class Overrides(StripeObject):
                class PartialPeriodBehavior(StripeObject):
                    class LicenseFee(StripeObject):
                        credit_proration_behavior: Literal["none", "prorated"]
                        """
                        The proration behavior for the partial servicing period. Defines how we prorate the license fee when the user modifies the subscription. If not specified, defaults to prorated.
                        """
                        debit_proration_behavior: Literal["none", "prorated"]
                        """
                        The proration behavior for the partial servicing period. Defines how we prorate the license fee when the user modifies the subscription. If not specified, defaults to prorated.
                        """

                    class RecurringCreditGrant(StripeObject):
                        create_behavior: Literal["full_credits", "none"]
                        """
                        Controls credit grant creation behavior during partial periods. If not specified, defaults to full_credits.
                        """

                    license_fee: Optional[LicenseFee]
                    """
                    Overrides the behavior for license fee components when the action takes effect during the service period.
                    """
                    recurring_credit_grant: Optional[RecurringCreditGrant]
                    """
                    Overrides the behavior for recurring credit grant components when the action takes effect during the service period.
                    """
                    type: Literal["license_fee", "recurring_credit_grant"]
                    """
                    The type of behavior to override.
                    """
                    _inner_class_types = {
                        "license_fee": LicenseFee,
                        "recurring_credit_grant": RecurringCreditGrant,
                    }

                partial_period_behaviors: List[PartialPeriodBehavior]
                """
                Configurations for behaviors when the action takes effect during the service period.
                """
                _inner_class_types = {
                    "partial_period_behaviors": PartialPeriodBehavior,
                }

            component_configurations: List[ComponentConfiguration]
            """
            New configurations for the components of the Pricing Plan.
            """
            new_pricing_plan: str
            """
            ID of the new Pricing Plan.
            """
            new_pricing_plan_version: str
            """
            Version of the Pricing Plan to use.
            """
            overrides: Optional[Overrides]
            """
            Configurations for overriding behaviors related to the subscription.
            """
            pricing_plan_subscription: str
            """
            ID of the Pricing Plan Subscription to modify.
            """
            _inner_class_types = {
                "component_configurations": ComponentConfiguration,
                "overrides": Overrides,
            }

        collect_at: Literal["next_billing_date", "on_effective_at"]
        """
        Allows users to override the collect at behavior.
        """
        effective_at: EffectiveAt
        """
        When the modify action takes effect. If not specified, the default behavior is on_reserve.
        """
        pricing_plan_subscription_details: Optional[
            PricingPlanSubscriptionDetails
        ]
        """
        Details for modifying a Pricing Plan Subscription.
        """
        type: Literal[
            "pricing_plan_subscription_details", "v1_subscription_details"
        ]
        """
        Type of the action details.
        """
        _inner_class_types = {
            "effective_at": EffectiveAt,
            "pricing_plan_subscription_details": PricingPlanSubscriptionDetails,
        }

    class Remove(StripeObject):
        class EffectiveAt(StripeObject):
            type: Literal["current_billing_period_end", "on_reserve"]
            """
            When the remove action takes effect.
            """

        effective_at: Optional[EffectiveAt]
        """
        When the remove action takes effect. If not specified, defaults to on_reserve.
        """
        invoice_discount_rule: Optional[str]
        """
        The ID of the discount rule to remove for future invoices.
        """
        spend_modifier_rule: Optional[str]
        """
        The ID of the spend modifier rule removed.
        """
        type: Literal["invoice_discount_rule", "spend_modifier_rule"]
        """
        Type of the remove action.
        """
        _inner_class_types = {"effective_at": EffectiveAt}

    class Subscribe(StripeObject):
        class EffectiveAt(StripeObject):
            timestamp: Optional[str]
            """
            The timestamp at which the subscribe action takes effect. Only present if type is timestamp.
            """
            type: Literal[
                "current_billing_period_start", "on_reserve", "timestamp"
            ]
            """
            When the subscribe action takes effect.
            """

        class PricingPlanSubscriptionDetails(StripeObject):
            class ComponentConfiguration(StripeObject):
                lookup_key: Optional[str]
                """
                Lookup key for the pricing plan component.
                """
                pricing_plan_component: Optional[str]
                """
                ID of the pricing plan component.
                """
                quantity: Optional[int]
                """
                Quantity of the component to be used.
                """

            class Overrides(StripeObject):
                class PartialPeriodBehavior(StripeObject):
                    class LicenseFee(StripeObject):
                        debit_proration_behavior: Literal["none", "prorated"]
                        """
                        The proration behavior for the partial servicing period. Defines how we prorate the license fee when the user is subscribing. If not specified, defaults to prorated.
                        """

                    class RecurringCreditGrant(StripeObject):
                        create_behavior: Literal["full_credits", "none"]
                        """
                        Controls credit grant creation behavior during partial periods. If not specified, defaults to full_credits.
                        """

                    license_fee: Optional[LicenseFee]
                    """
                    Overrides the behavior for license fee components when the action takes effect during the service period.
                    """
                    recurring_credit_grant: Optional[RecurringCreditGrant]
                    """
                    Overrides the behavior for recurring credit grant components when the action takes effect during the service period.
                    """
                    type: Literal["license_fee", "recurring_credit_grant"]
                    """
                    The type of behavior to override.
                    """
                    _inner_class_types = {
                        "license_fee": LicenseFee,
                        "recurring_credit_grant": RecurringCreditGrant,
                    }

                partial_period_behaviors: List[PartialPeriodBehavior]
                """
                Configurations for behaviors when the action takes effect during the service period.
                """
                _inner_class_types = {
                    "partial_period_behaviors": PartialPeriodBehavior,
                }

            component_configurations: List[ComponentConfiguration]
            """
            Configurations for the components of the Pricing Plan.
            """
            metadata: Optional[UntypedStripeObject[str]]
            """
            Set of [key-value pairs](https://docs.stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
            """
            overrides: Optional[Overrides]
            """
            Configurations for overriding behaviors related to the subscription.
            """
            pricing_plan: str
            """
            ID of the Pricing Plan to subscribe to.
            """
            pricing_plan_subscription: Optional[str]
            """
            ID of the created Pricing Plan Subscription. This is only present once the Billing Intent is committed and the Pricing Plan Subscription is created.
            """
            pricing_plan_version: str
            """
            Version of the Pricing Plan to use.
            """
            _inner_class_types = {
                "component_configurations": ComponentConfiguration,
                "overrides": Overrides,
            }

        class V1SubscriptionDetails(StripeObject):
            class Item(StripeObject):
                metadata: Optional[UntypedStripeObject[str]]
                """
                Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
                """
                price: str
                """
                The ID of the price object.
                """
                quantity: Optional[int]
                """
                Quantity for this item. If not provided, defaults to 1.
                """

            description: Optional[str]
            """
            The subscription's description, meant to be displayable to the customer.
            Use this field to optionally store an explanation of the subscription for rendering in Stripe surfaces and certain local payment methods UIs.
            """
            items: List[Item]
            """
            A list of up to 20 subscription items, each with an attached price.
            """
            metadata: Optional[UntypedStripeObject[str]]
            """
            Set of key-value pairs that you can attach to an object. This can be useful for storing additional information about the object in a structured format.
            """
            _inner_class_types = {"items": Item}

        collect_at: Literal["next_billing_date", "on_effective_at"]
        """
        Allows users to override the collect at behavior.
        """
        effective_at: EffectiveAt
        """
        When the subscribe action takes effect. If not specified, the default behavior is on_reserve.
        """
        pricing_plan_subscription_details: Optional[
            PricingPlanSubscriptionDetails
        ]
        """
        Details for subscribing to a Pricing Plan.
        """
        type: Literal[
            "pricing_plan_subscription_details", "v1_subscription_details"
        ]
        """
        Type of the action details.
        """
        v1_subscription_details: Optional[V1SubscriptionDetails]
        """
        Details for subscribing to a V1 subscription.
        """
        _inner_class_types = {
            "effective_at": EffectiveAt,
            "pricing_plan_subscription_details": PricingPlanSubscriptionDetails,
            "v1_subscription_details": V1SubscriptionDetails,
        }

    apply: Optional[Apply]
    """
    Details for an apply action.
    """
    created: str
    """
    Time at which the object was created.
    """
    deactivate: Optional[Deactivate]
    """
    Details for a deactivate action.
    """
    id: str
    """
    Unique identifier for the object.
    """
    livemode: bool
    """
    Has the value `true` if the object exists in live mode or the value `false` if the object exists in test mode.
    """
    modify: Optional[Modify]
    """
    Details for a modify action.
    """
    object: Literal["v2.billing.intent_action"]
    """
    String representing the object's type. Objects of the same type share the same value of the object field.
    """
    remove: Optional[Remove]
    """
    Details for a remove action.
    """
    subscribe: Optional[Subscribe]
    """
    Details for a subscribe action.
    """
    type: Literal["apply", "deactivate", "modify", "remove", "subscribe"]
    """
    Type of the Billing Intent Action.
    """
    _inner_class_types = {
        "apply": Apply,
        "deactivate": Deactivate,
        "modify": Modify,
        "remove": Remove,
        "subscribe": Subscribe,
    }
