{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.revenexx.com/billing.schema.json",
  "title": "revenexx App Billing",
  "description": "Marketplace billing declaration for a revenexx App. Defines how the app is priced and distributed. Without billing.json, the app is private to the vendor. Required for App Marketplace distribution. NOTE: Billing model is an open decision — this schema is a first PoC implementation.",
  "type": "object",
  "required": ["type"],
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "type": "string",
      "description": "Reference to this JSON Schema for editor validation and autocompletion."
    },
    "type": {
      "type": "string",
      "enum": ["free", "paid", "included"],
      "description": "'free' — available at no cost in the Marketplace. 'paid' — requires a subscription plan (processed via Chargebee). 'included' — bundled with the Customer's billing package (no separate charge, activated by Console based on package)."
    },
    "support": {
      "type": "object",
      "description": "Support contact information displayed in the Marketplace and Cockpit.",
      "additionalProperties": false,
      "properties": {
        "email": {
          "type": "string",
          "format": "email",
          "description": "Support email address."
        },
        "url": {
          "type": "string",
          "format": "uri",
          "description": "Support website or documentation URL."
        }
      }
    },
    "plans": {
      "type": "array",
      "description": "Pricing plans. Required when type is 'paid'. Each plan maps to a Chargebee plan.",
      "items": {
        "$ref": "#/$defs/plan"
      },
      "minItems": 1
    },
    "trial": {
      "type": "object",
      "description": "Optional trial period before billing starts.",
      "additionalProperties": false,
      "properties": {
        "days": {
          "type": "integer",
          "minimum": 1,
          "maximum": 90,
          "description": "Number of free trial days."
        }
      }
    },
    "categories": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "uniqueItems": true,
      "description": "Marketplace categories for discoverability (e.g. 'commerce', 'marketing', 'integration', 'analytics')."
    },
    "available_countries": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^([A-Z]{2}|\\*)$"
      },
      "description": "ISO 3166-1 alpha-2 country codes where this app is available. Omit or use ['*'] for all countries.",
      "default": ["*"]
    }
  },
  "$defs": {
    "plan": {
      "type": "object",
      "required": ["id", "name", "currency", "price"],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9-]*$",
          "description": "Unique plan identifier. Maps to a Chargebee plan ID."
        },
        "name": {
          "type": "string",
          "description": "Human-readable plan name displayed in the Marketplace (e.g. 'Starter', 'Professional', 'Enterprise')."
        },
        "description": {
          "type": "string",
          "description": "Short description of what this plan includes."
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$",
          "description": "ISO 4217 currency code (e.g. 'EUR', 'USD')."
        },
        "price": {
          "type": "object",
          "required": ["monthly"],
          "additionalProperties": false,
          "properties": {
            "monthly": {
              "type": "number",
              "minimum": 0,
              "description": "Monthly subscription price in the specified currency."
            },
            "yearly": {
              "type": "number",
              "minimum": 0,
              "description": "Optional yearly price (typically discounted vs 12x monthly)."
            }
          }
        },
        "features": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "List of feature descriptions included in this plan. Displayed as a bullet list in the Marketplace."
        },
        "limits": {
          "type": "object",
          "description": "Optional usage limits for this plan.",
          "additionalProperties": {
            "type": "number"
          }
        }
      }
    }
  }
}
