{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://okstra.dev/schemas/report-synthesis-packet-v1.0.schema.json",
  "title": "Okstra report synthesis packet",
  "type": "object",
  "required": [
    "schemaVersion",
    "taskKey",
    "taskType",
    "authoringContract",
    "accountingSnapshot",
    "sources"
  ],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": {
      "const": "1.0"
    },
    "taskKey": {
      "type": "string",
      "minLength": 1
    },
    "taskType": {
      "type": "string",
      "minLength": 1
    },
    "authoringContract": {
      "type": "object",
      "required": [
        "resultPath",
        "format",
        "sourcePolicy",
        "instructions",
        "runtimeOwnedContent",
        "validationRules"
      ],
      "additionalProperties": false,
      "properties": {
        "resultPath": {
          "type": "string",
          "minLength": 1
        },
        "format": {
          "const": "report-narrative-v3.0"
        },
        "sourcePolicy": {
          "const": "read-only-synthesis-packet"
        },
        "instructions": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "runtimeOwnedContent": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "validationRules": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "accountingSnapshot": {
      "type": "object",
      "required": [
        "leadSessionIds",
        "leadUsage",
        "workerUsage",
        "usageSummary"
      ],
      "additionalProperties": false,
      "properties": {
        "leadSessionIds": {
          "type": "array",
          "items": {"type": "string"}
        },
        "leadUsage": {"type": "object"},
        "workerUsage": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["workerId", "role", "usage"],
            "additionalProperties": false,
            "properties": {
              "workerId": {"type": "string", "minLength": 1},
              "role": {"type": "string"},
              "usage": {"type": "object"}
            }
          }
        },
        "usageSummary": {"type": "object"}
      }
    },
    "sources": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["label", "owner", "path", "digest", "content"],
        "additionalProperties": false,
        "properties": {
          "label": {
            "type": "string",
            "minLength": 1
          },
          "owner": {
            "type": "string",
            "minLength": 1
          },
          "path": {
            "type": "string",
            "minLength": 1
          },
          "digest": {
            "type": "string",
            "pattern": "^sha256:[0-9a-f]{64}$"
          },
          "content": {
            "type": "string"
          }
        }
      }
    }
  }
}
