{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://agenticdecks.com/schemas/v1/deckrun-user-account.json",
  "$comment": "© 2026 Agentic Decks. Publicly readable. Not open source. See https://agenticdecks.com/schemas for usage terms.",
  "title": "Deckrun user account",
  "description": "User account resource returned by GET /me. Cursor-style: every account has a plan tier and a credits object (period allowance + used; optional balance). Team and enterprise include seats (used/available, GitHub-style). See https://agenticdecks.com/docs/ for how plan and credits work for Teams vs Enterprise.",
  "type": "object",
  "properties": {
    "account_id": {
      "type": "string",
      "description": "Unique account identifier (maps to user or organization depending on account type)."
    },
    "plan": {
      "type": "string",
      "enum": ["basic", "plus", "pro", "max", "team", "enterprise"],
      "description": "Tier. basic/plus/pro/max = individual; team = multi-seat, per-user allowance; enterprise = org-level, pooled credits, SSO, SLA. organization typically present for team/enterprise."
    },
    "credits": {
      "type": "object",
      "description": "Credits for this account: period allowance, used this period, optional balance. Always present. For individual and team (member view) = this user's slice; for enterprise org = pooled.",
      "properties": {
        "balance": {
          "type": "integer",
          "minimum": 0,
          "description": "Current available credits (e.g. top-up). Decremented on consumption."
        },
        "period_allowance": {
          "type": "integer",
          "minimum": 0,
          "description": "Credits granted per billing period (e.g. 500/month). Zero for free tier."
        },
        "period_start": {
          "type": "string",
          "format": "date-time",
          "description": "Start of current credits period."
        },
        "period_end": {
          "type": "string",
          "format": "date-time",
          "description": "End of current credits period."
        },
        "used_this_period": {
          "type": "integer",
          "minimum": 0,
          "description": "Credits consumed in the current period (display: used_this_period of period_allowance)."
        },
        "scope": {
          "type": "string",
          "enum": ["user", "organization"],
          "description": "Optional. user = this user's allowance/usage; organization = pooled or org-wide (enterprise or org-level view). If omitted, defaults to user for individual/team member views."
        }
      },
      "additionalProperties": false
    },
    "seats": {
      "type": "object",
      "description": "Present for plan team or enterprise (GitHub-style). used = seats in use; available = total licensed capacity. Free seats = available − used.",
      "properties": {
        "used": { "type": "integer", "minimum": 0, "description": "Seats currently in use." },
        "available": { "type": "integer", "minimum": 0, "description": "Total seats licensed (capacity)." }
      },
      "additionalProperties": false
    },
    "connectors": {
      "type": "object",
      "description": "Storage connector usage. used = current connector count; limit = max allowed by plan (-1 = unlimited). See OpenAPI x-connector-limits for per-plan defaults.",
      "properties": {
        "used": { "type": "integer", "minimum": 0, "description": "Number of connectors currently configured." },
        "limit": { "type": "integer", "minimum": -1, "description": "Max connectors allowed by plan; -1 = unlimited." }
      },
      "additionalProperties": false
    },
    "email": { "type": "string", "format": "email", "description": "Account email (if available; may be omitted for key-only access)." },
    "name": { "type": "string", "description": "Display name for the account (optional)." },
    "identity_sub": {
      "type": "string",
      "description": "Identity provider subject (stable, never changes; used for AuthN linking)."
    },
    "default_slide_theme_id": {
      "type": "string",
      "description": "ID of the account default slide theme, if set. Omit in POST /generate to use this default."
    },
    "subscription_expires_at": {
      "type": "string",
      "format": "date-time",
      "description": "When the current subscription period ends. Past date implies expired; service may treat as basic at read time."
    },
    "billing_status": {
      "type": "string",
      "enum": ["active", "past_due", "canceled", "trialing"],
      "description": "Billing status for the account (from subscription/organization)."
    },
    "billing_email": { "type": "string", "format": "email", "description": "Email used for billing (may differ from account email)." },
    "organization": {
      "type": "object",
      "description": "Optional. When account is org-scoped (multi-tenant), the primary organization. Typically present when plan is team or enterprise.",
      "properties": {
        "id": { "type": "string" },
        "name": { "type": "string" },
        "slug": { "type": "string" }
      }
    },
    "created_at": { "type": "string", "format": "date-time", "description": "Account creation timestamp (optional)." },
    "updated_at": { "type": "string", "format": "date-time", "description": "Last account/subscription update (optional)." }
  },
  "required": ["account_id", "plan", "credits"],
  "allOf": [
    {
      "if": { "properties": { "plan": { "enum": ["team", "enterprise"] } } },
      "then": { "required": ["seats"] }
    }
  ]
}
