{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://loop.firmiana.si/plans/v1/plans.schema.json",
  "title": "AI subscription plans dataset (v1/plans.json)",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "version", "generated_at", "license", "homepage", "repository", "fx", "vendors", "plans"],
  "properties": {
    "schema": { "type": "string", "format": "uri" },
    "version": { "const": 1 },
    "generated_at": { "type": "string", "format": "date-time" },
    "license": { "const": "CC-BY-4.0" },
    "homepage": { "type": "string", "format": "uri" },
    "repository": { "type": "string", "format": "uri" },
    "fx": {
      "type": "object",
      "description": "Exchange rates used ONLY for the converted fields. Official prices are never converted in place.",
      "additionalProperties": false,
      "required": ["date", "source", "source_url", "base", "per_usd"],
      "properties": {
        "date": { "type": "string", "format": "date" },
        "source": { "type": "string" },
        "source_url": { "type": "string", "format": "uri" },
        "base": { "const": "USD" },
        "per_usd": { "type": "object", "additionalProperties": { "type": "number", "exclusiveMinimum": 0 } }
      }
    },
    "vendors": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "name", "name_zh", "region", "website", "pages", "products"],
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "name_zh": { "type": "string" },
          "region": { "enum": ["intl", "cn"] },
          "website": { "type": "string", "format": "uri" },
          "pages": { "type": "array", "items": { "type": "string", "format": "uri" } },
          "products": { "type": "array", "items": { "type": "string" } }
        }
      }
    },
    "plans": { "type": "array", "items": { "$ref": "#/$defs/plan" } }
  },
  "$defs": {
    "text": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["en", "zh"],
      "properties": { "en": { "type": "string" }, "zh": { "type": "string" } }
    },
    "amount": { "oneOf": [{ "type": "number", "minimum": 0 }, { "type": "null" }, { "const": "unverified" }] },
    "item": {
      "type": "object",
      "additionalProperties": false,
      "required": ["en", "zh", "unverified", "source"],
      "properties": {
        "en": { "type": "string" },
        "zh": { "type": "string" },
        "unverified": { "type": "boolean" },
        "source": { "type": ["string", "null"], "format": "uri" }
      }
    },
    "converted": {
      "type": "object",
      "additionalProperties": false,
      "required": ["rate", "monthly", "annual"],
      "properties": {
        "rate": { "type": "number", "description": "Units of the target currency per 1 unit of the official currency." },
        "monthly": { "$ref": "#/$defs/amount" },
        "annual": { "$ref": "#/$defs/amount" }
      }
    },
    "price": {
      "type": "object",
      "additionalProperties": false,
      "required": ["region", "currency", "monthly", "annual", "per_seat", "tax", "note", "source", "verified", "converted"],
      "properties": {
        "region": { "type": "string" },
        "currency": { "type": "string", "pattern": "^[A-Z]{3}$" },
        "monthly": { "$ref": "#/$defs/amount", "description": "Official price of one month on monthly billing, in `currency`." },
        "annual": { "$ref": "#/$defs/amount", "description": "Official total for one year on annual billing, in `currency`." },
        "per_seat": { "type": "boolean" },
        "tax": { "enum": ["excluded", "included", "unknown"] },
        "note": { "$ref": "#/$defs/text" },
        "source": { "type": "string", "format": "uri" },
        "verified": { "type": "string", "format": "date" },
        "converted": {
          "type": "object",
          "description": "Display-only conversions at the rates in `fx` (fx_date). Not official prices.",
          "required": ["fx_date"],
          "properties": {
            "fx_date": { "type": "string", "format": "date" },
            "USD": { "$ref": "#/$defs/converted" },
            "CNY": { "$ref": "#/$defs/converted" },
            "EUR": { "$ref": "#/$defs/converted" }
          },
          "additionalProperties": false
        }
      }
    },
    "plan": {
      "type": "object",
      "additionalProperties": false,
      "required": ["key", "vendor", "vendor_name", "vendor_name_zh", "vendor_region", "product", "product_name", "product_name_zh",
        "product_url", "category", "plan", "plan_name", "plan_name_zh", "audience", "free", "monthly_usd_equiv", "prices",
        "models", "limits", "features", "note", "product_note", "has_unverified", "sources", "verified"],
      "properties": {
        "key": { "type": "string", "pattern": "^[a-z0-9-]+/[a-z0-9-]+/[a-z0-9-]+$" },
        "vendor": { "type": "string" },
        "vendor_name": { "type": "string" },
        "vendor_name_zh": { "type": "string" },
        "vendor_region": { "enum": ["intl", "cn"] },
        "product": { "type": "string" },
        "product_name": { "type": "string" },
        "product_name_zh": { "type": "string" },
        "product_url": { "type": "string", "format": "uri" },
        "category": { "enum": ["chat", "coding"] },
        "plan": { "type": "string" },
        "plan_name": { "type": "string" },
        "plan_name_zh": { "type": "string" },
        "audience": { "enum": ["individual", "team"] },
        "free": { "type": "boolean" },
        "monthly_usd_equiv": { "type": ["number", "null"], "description": "Main monthly price converted to USD for sorting and filtering (null if not published)." },
        "prices": { "type": "array", "items": { "$ref": "#/$defs/price" }, "description": "prices[0] is the main (global) price when there is one." },
        "models": { "type": "array", "items": { "$ref": "#/$defs/item" } },
        "limits": { "type": "array", "items": { "$ref": "#/$defs/item" } },
        "features": { "type": "array", "items": { "$ref": "#/$defs/item" } },
        "note": { "$ref": "#/$defs/text" },
        "product_note": { "$ref": "#/$defs/text" },
        "has_unverified": { "type": "boolean" },
        "sources": { "type": "array", "items": { "type": "string", "format": "uri" } },
        "verified": { "type": "string", "format": "date" }
      }
    }
  }
}
