{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://loop.firmiana.si/push/v1/events.schema.json",
  "title": "Loop change feed: new models and plans, price changes, retirements, major outages and livestreams",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "version", "generated_at", "license", "types", "vendors", "events"],
  "properties": {
    "schema": { "const": "https://loop.firmiana.si/push/v1/events.schema.json" },
    "version": { "const": 1 },
    "generated_at": { "type": "string", "format": "date-time" },
    "license": { "const": "CC-BY-4.0" },
    "types": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "en", "zh"],
        "properties": { "id": { "$ref": "#/$defs/type" }, "en": { "type": "string" }, "zh": { "type": "string" } }
      }
    },
    "vendors": {
      "type": "array",
      "description": "Every vendor an event can name, for filters",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["id", "name", "name_zh"],
        "properties": { "id": { "$ref": "#/$defs/vendor" }, "name": { "type": "string" }, "name_zh": { "type": "string" } }
      }
    },
    "events": { "type": "array", "description": "Newest first, last 30 days", "items": { "$ref": "#/$defs/event" } }
  },
  "$defs": {
    "type": { "enum": ["new", "price", "retire", "outage", "live"] },
    "vendor": { "type": "string", "pattern": "^[a-z0-9][a-z0-9-]{0,40}$" },
    "text": {
      "type": "object",
      "additionalProperties": false,
      "required": ["en", "zh"],
      "properties": { "en": { "type": "string", "maxLength": 400 }, "zh": { "type": "string", "maxLength": 400 } }
    },
    "event": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "type", "time", "vendor", "vendor_name", "title", "summary", "url", "page", "change", "subject", "phase", "ref"],
      "properties": {
        "id": { "type": "string", "minLength": 3, "maxLength": 200, "description": "Stable; the same change always has the same id" },
        "type": { "$ref": "#/$defs/type" },
        "time": { "type": "string", "format": "date-time", "description": "When the change happened or was first seen (UTC)" },
        "vendor": { "$ref": "#/$defs/vendor" },
        "vendor_name": { "$ref": "#/$defs/text" },
        "title": { "$ref": "#/$defs/text" },
        "summary": { "oneOf": [{ "$ref": "#/$defs/text" }, { "type": "null" }] },
        "url": { "type": "string", "format": "uri", "pattern": "^https://", "description": "Official source" },
        "page": { "type": ["string", "null"], "format": "uri", "description": "The Loop page about it" },
        "change": { "enum": ["new-model", "new", "cut", "increase", "change", "removed", null], "description": "Catalog events: what kind of change, for one-line layouts" },
        "subject": { "oneOf": [{ "$ref": "#/$defs/text" }, { "type": "null" }], "description": "Catalog events: the model or plan name" },
        "phase": { "enum": ["opened", "resolved", null], "description": "Outages: the incident began (or was first seen) or ended" },
        "ref": { "type": ["string", "null"], "description": "Resolved outages: the id of the opened event" }
      }
    }
  }
}
