"""API models for billing checkout operations."""

from typing import Any

from pydantic import BaseModel, Field


class CreateCheckoutRequest(BaseModel):
  """Request to create a checkout session for payment collection."""

  plan_name: str = Field(
    ..., description="Billing plan name (e.g., 'ladybug-standard')"
  )
  resource_type: str = Field(..., description="Resource type ('graph' or 'repository')")
  resource_config: dict[str, Any] = Field(
    ...,
    description="Configuration for the resource to be provisioned. "
    "For repositories: {'repository_name': 'graph_id'} where graph_id is the repository slug (e.g., 'sec')",
  )


class CheckoutResponse(BaseModel):
  """Response from checkout session creation."""

  checkout_url: str | None = Field(
    None, description="URL to redirect user to for payment"
  )
  session_id: str | None = Field(
    None, description="Checkout session ID for status polling"
  )
  subscription_id: str | None = Field(None, description="Internal subscription ID")
  requires_checkout: bool = Field(
    default=True, description="Whether checkout is required"
  )
  billing_disabled: bool = Field(
    default=False, description="Whether billing is disabled on this instance"
  )


class CheckoutStatusResponse(BaseModel):
  """Status of a checkout session."""

  status: str = Field(
    ...,
    description="Checkout status: 'pending_payment', 'provisioning', 'active', 'failed', 'canceled'",
  )
  subscription_id: str = Field(..., description="Internal subscription ID")
  resource_id: str | None = Field(
    None,
    description="Resource ID (graph_id for both graphs and repositories) once provisioned. "
    "For repositories, this is the repository slug (e.g., 'sec')",
  )
  operation_id: str | None = Field(
    None, description="SSE operation ID for monitoring provisioning progress"
  )
  error: str | None = Field(None, description="Error message if checkout failed")
