"""
Subscription domain enumerations.
"""

from enum import Enum
from src.core.utils.enums import WellDocumentedIntEnum


class SubscriptionStatus(WellDocumentedIntEnum):
    """
    Lifecycle status for a Subscription record.

    Status flow (happy path):
        INITIALIZING → ACTIVE → COMPLETED
                             ↘ CANCELLED
                             ↘ PAST_DUE → (ACTIVE after successful retry)
                                        → DUNNING_EXHAUSTED

    PAUSED is an explicit merchant-initiated hold that can resume to ACTIVE.
    """

    INITIALIZING = 100
    # Record created; waiting for first payment method to be authorized and
    # the first billing cycle to be scheduled.

    ACTIVE = 200
    # Subscription is running normally.  next_billing_date is set and
    # Celery will attempt a charge on that date.

    PAST_DUE = 201
    # Last charge attempt failed.  past_due_since is stamped.
    # Dunning retries are scheduled (dunning_next_retry_at).

    PAUSED = 202
    # Merchant explicitly paused the subscription.
    # No charges will be attempted until resumed.

    CANCELLED = 300
    # Permanently stopped.  No further charges will be attempted.
    # Set by merchant action or automatically after dunning is exhausted.

    COMPLETED = 301
    # All billing cycles successfully completed (end_type = UNTIL_COUNT
    # reached its target, or end_date passed with final payment collected).

    EXPIRED = 302
    # Date-based end condition reached (end_type=DATE) and all generated
    # invoices were successfully paid.  No further charges will occur.

    DUNNING_EXHAUSTED = 400
    # Max dunning retries exceeded without a successful payment.
    # Subscription auto-cancelled; merchant is notified.


class SubscriptionActivityTypes(str, Enum):
    """Activity type strings for SubscriptionActivity records."""

    CREATED = "subscription.created"
    ACTIVATED = "subscription.activated"
    PAUSED = "subscription.paused"
    RESUMED = "subscription.resumed"
    CANCELLED = "subscription.cancelled"
    COMPLETED = "subscription.completed"
    CHARGE_SUCCEEDED = "subscription.charge_succeeded"
    CHARGE_FAILED = "subscription.charge_failed"
    DUNNING_RETRY_SCHEDULED = "subscription.dunning_retry_scheduled"
    DUNNING_RETRY_ATTEMPTED = "subscription.dunning_retry_attempted"
    DUNNING_EXHAUSTED = "subscription.dunning_exhausted"
    INVOICE_GENERATED = "subscription.invoice_generated"
    INVOICE_AUTO_GENERATED = "subscription.invoice_auto_generated"
    PAYMENT_METHOD_UPDATED = "subscription.payment_method_updated"
    REAUTH_REQUESTED = "subscription.reauth_requested"
    STATUS_CHANGED = "subscription.status_changed"
    STATUS_AUTO_UPDATED = "subscription.status_auto_updated"
    CHARGE_NOW_INITIATED = "subscription.charge_now_initiated"
