"""Pydantic models for billing domain objects."""

from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, Field


class Subscription(BaseModel):
    """Represents an active or past subscription."""

    id: str
    user_id: str
    plan_name: str
    status: str = Field(description="Stripe subscription status (active, canceled, past_due, etc.)")
    current_period_start: datetime
    current_period_end: datetime
    cancel_at_period_end: bool = False


class Invoice(BaseModel):
    """Represents a Stripe invoice."""

    id: str
    amount: int = Field(description="Amount in smallest currency unit (e.g., cents)")
    currency: str
    status: str
    created: datetime
    pdf_url: str | None = None


class UsageRecord(BaseModel):
    """Represents a metered usage record."""

    user_id: str
    metric: str
    quantity: int
    timestamp: datetime = Field(default_factory=datetime.now)


class CheckoutSession(BaseModel):
    """Result of creating a Stripe Checkout session."""

    url: str = Field(description="Redirect URL for the checkout page")
    session_id: str


class WebhookEvent(BaseModel):
    """Parsed and verified Stripe webhook event."""

    type: str = Field(description="Stripe event type (e.g., checkout.session.completed)")
    data: dict = Field(default_factory=dict, description="Event payload data")
