{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rendlio.com/schemas/compat-report/v1.json",
  "$comment": "Family scope: the envelope core (schemaVersion, engine, input, options, mode, result, warnings, timings) is shared by every Rendlio engine; the remaining sections are grid-engine payload. This schema is never extended to carry another format — see docs/FS/FS-09-compat-report.md §2 'Family scope of this contract'.",
  "title": "Rendlio Compatibility Report",
  "type": "object",
  "required": ["schemaVersion", "engine", "input", "options", "mode", "result", "pages", "sheets", "features", "fonts", "formulas", "warnings", "timings"],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": { "type": "string", "pattern": "^1\\.[0-9]+$" },
    "engine": {
      "type": "object",
      "required": ["name", "version", "releaseDate"],
      "additionalProperties": false,
      "properties": {
        "name": { "const": "Rendlio" },
        "version": { "type": "string" },
        "releaseDate": { "type": "string", "format": "date" }
      }
    },
    "input": {
      "type": "object",
      "required": ["sha256", "sizeBytes"],
      "additionalProperties": false,
      "properties": {
        "sha256": { "type": "string", "pattern": "^[0-9a-f]{64}$" },
        "sizeBytes": { "type": "integer", "minimum": 0 },
        "fileName": { "type": "string" }
      }
    },
    "options": { "type": "object" },
    "mode": { "enum": ["convert", "diagnose"] },
    "result": {
      "type": "object",
      "required": ["status", "exitCode"],
      "additionalProperties": false,
      "properties": {
        "status": { "enum": ["success", "warnings", "unsupported-content", "invalid-input", "resource-limit", "error"] },
        "exitCode": { "type": "integer", "minimum": 0, "maximum": 5 }
      }
    },
    "pages": {
      "type": "object",
      "required": ["count"],
      "additionalProperties": false,
      "properties": { "count": { "type": "integer", "minimum": 0 } }
    },
    "sheets": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["name", "index", "printed"],
        "additionalProperties": false,
        "properties": {
          "name": { "type": "string" },
          "index": { "type": "integer", "minimum": 0 },
          "printed": { "type": "boolean" }
        }
      }
    },
    "features": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["id", "status", "count"],
        "additionalProperties": false,
        "properties": {
          "id": { "type": "string", "pattern": "^F-(PARSE|STY|NUM|LAY|CF|CHT|IMG|TXT|PDF|PNG|REC|LIC|SEC)-[a-z0-9-]+$" },
          "status": { "enum": ["rendered", "approximated", "unsupported", "skipped"] },
          "count": { "type": "integer", "minimum": 1 },
          "locations": { "type": "array", "maxItems": 20, "items": { "$ref": "#/$defs/location" } },
          "locationsTruncated": { "type": "boolean" },
          "detail": { "type": "string" }
        }
      }
    },
    "fonts": {
      "type": "object",
      "required": ["substitutions", "missing"],
      "additionalProperties": false,
      "properties": {
        "substitutions": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["requested", "used", "reason"],
            "additionalProperties": false,
            "properties": {
              "requested": { "type": "string" },
              "used": { "type": "string" },
              "reason": { "enum": ["metric-substitute", "fallback", "missing-default"] }
            }
          }
        },
        "missing": { "type": "array", "items": { "type": "string" } }
      }
    },
    "formulas": {
      "type": "object",
      "required": ["cellsTotal", "cachedMissing", "recalcMode"],
      "additionalProperties": false,
      "properties": {
        "cellsTotal": { "type": "integer", "minimum": 0 },
        "cachedMissing": { "type": "integer", "minimum": 0 },
        "recalcMode": { "enum": ["off", "strict-v1"] },
        "closureSize": { "type": ["integer", "null"], "minimum": 0 }
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["code", "severity", "message"],
        "additionalProperties": false,
        "properties": {
          "code": { "type": "string", "pattern": "^W[0-9]{4}$" },
          "severity": { "enum": ["info", "warn", "error"] },
          "message": { "type": "string" },
          "location": { "$ref": "#/$defs/location" }
        }
      }
    },
    "timings": {
      "type": "object",
      "required": ["parseMs", "layoutMs", "renderMs", "totalMs"],
      "additionalProperties": false,
      "properties": {
        "parseMs": { "type": "number", "minimum": 0 },
        "layoutMs": { "type": "number", "minimum": 0 },
        "renderMs": { "type": "number", "minimum": 0 },
        "totalMs": { "type": "number", "minimum": 0 }
      }
    }
  },
  "$defs": {
    "location": {
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "properties": {
        "sheet": { "type": ["string", "null"] },
        "ref": { "type": ["string", "null"] },
        "objectId": { "type": ["string", "null"] }
      }
    }
  }
}
