{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://loop.firmiana.si/status/v1/incidents.schema.json",
  "title": "LLM API incidents and uptime (v1/incidents.json)",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "generated_at",
    "window_days",
    "providers",
    "incidents"
  ],
  "properties": {
    "version": {
      "const": 1
    },
    "generated_at": {
      "type": "string",
      "format": "date-time"
    },
    "window_days": {
      "type": "integer",
      "minimum": 1
    },
    "providers": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/provider"
      }
    },
    "incidents": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/incident"
      }
    }
  },
  "$defs": {
    "ratio": {
      "type": [
        "number",
        "null"
      ],
      "minimum": 0,
      "maximum": 1
    },
    "period": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "availability",
        "incident_minutes",
        "incidents"
      ],
      "properties": {
        "availability": {
          "$ref": "#/$defs/ratio",
          "description": "1 - (minutes with an open API incident) / (minutes in the period); null when there is no data"
        },
        "incident_minutes": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "description": "Minutes with at least one open API incident (overlaps counted once)"
        },
        "incidents": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "description": "API incidents that started in the period"
        }
      }
    },
    "provider": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "region",
        "status_page",
        "note",
        "api_pattern",
        "last_checked",
        "fetch_ok",
        "last_24h",
        "window",
        "daily",
        "monthly"
      ],
      "properties": {
        "id": {
          "type": "string"
        },
        "name": {
          "type": "string"
        },
        "region": {
          "enum": [
            "intl",
            "cn"
          ]
        },
        "status_page": {
          "type": [
            "string",
            "null"
          ],
          "format": "uri",
          "description": "null = the provider has no official status page"
        },
        "note": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": false,
          "required": [
            "en",
            "zh"
          ],
          "properties": {
            "en": {
              "type": "string"
            },
            "zh": {
              "type": "string"
            }
          }
        },
        "api_pattern": {
          "type": [
            "string",
            "null"
          ],
          "description": "Regular expression on component names that marks an incident as affecting the API"
        },
        "last_checked": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "fetch_ok": {
          "type": [
            "boolean",
            "null"
          ],
          "description": "Whether the last scheduled read of the status page worked (null when not known for this build)"
        },
        "last_24h": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "incidents",
            "api_incidents",
            "ongoing"
          ],
          "properties": {
            "incidents": {
              "type": "integer",
              "minimum": 0
            },
            "api_incidents": {
              "type": "integer",
              "minimum": 0
            },
            "ongoing": {
              "type": "integer",
              "minimum": 0
            }
          }
        },
        "window": {
          "$ref": "#/$defs/period"
        },
        "daily": {
          "type": "array",
          "description": "One entry per UTC day of the window, oldest first",
          "items": {
            "$ref": "#/$defs/daily"
          }
        },
        "monthly": {
          "type": "array",
          "description": "Calendar months overlapping the window (the first is partial)",
          "items": {
            "$ref": "#/$defs/monthly"
          }
        }
      }
    },
    "incident": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "provider",
        "id",
        "title",
        "url",
        "started_at",
        "resolved_at",
        "duration_minutes",
        "ongoing",
        "severity",
        "severity_raw",
        "components",
        "api",
        "updated_at"
      ],
      "properties": {
        "provider": {
          "type": "string"
        },
        "id": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "url": {
          "type": "string",
          "format": "uri"
        },
        "started_at": {
          "type": "string",
          "format": "date-time"
        },
        "resolved_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "duration_minutes": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "description": "null while ongoing"
        },
        "ongoing": {
          "type": "boolean"
        },
        "severity": {
          "enum": [
            "none",
            "minor",
            "major",
            "critical",
            "unknown"
          ]
        },
        "severity_raw": {
          "type": [
            "string",
            "null"
          ]
        },
        "components": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "api": {
          "type": "boolean",
          "description": "Affects the API (see the provider's api_pattern); only these count toward availability"
        },
        "updated_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        }
      }
    },
    "daily": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "date",
        "availability",
        "incident_minutes",
        "incidents"
      ],
      "properties": {
        "date": {
          "type": "string",
          "format": "date"
        },
        "availability": {
          "$ref": "#/$defs/ratio",
          "description": "1 - (minutes with an open API incident) / (minutes in the period); null when there is no data"
        },
        "incident_minutes": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "description": "Minutes with at least one open API incident (overlaps counted once)"
        },
        "incidents": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "description": "API incidents that started in the period"
        }
      }
    },
    "monthly": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "month",
        "availability",
        "incident_minutes",
        "incidents"
      ],
      "properties": {
        "month": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}$"
        },
        "availability": {
          "$ref": "#/$defs/ratio",
          "description": "1 - (minutes with an open API incident) / (minutes in the period); null when there is no data"
        },
        "incident_minutes": {
          "type": [
            "number",
            "null"
          ],
          "minimum": 0,
          "description": "Minutes with at least one open API incident (overlaps counted once)"
        },
        "incidents": {
          "type": [
            "integer",
            "null"
          ],
          "minimum": 0,
          "description": "API incidents that started in the period"
        }
      }
    }
  }
}
