{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://raw.githubusercontent.com/yviscool/Genesis/main/manifest.schema.json",
  "title": "Genesis Dataset Manifest v2",
  "type": "object",
  "additionalProperties": false,
  "required": ["version", "tool", "generatedAt", "dataset", "execution", "replay", "summary", "cases"],
  "properties": {
    "version": { "const": 2 },
    "tool": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version"],
      "properties": {
        "name": { "const": "genesis-kit" },
        "version": { "type": "string", "minLength": 1 }
      }
    },
    "generatedAt": { "type": "string", "format": "date-time" },
    "dataset": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "modulePath",
        "solution",
        "outputDir",
        "seed",
        "startFrom",
        "runTimeoutMs",
        "caseConcurrency",
        "compiler",
        "compilerFlags",
        "ojProfile",
        "stackSizeBytes",
        "manifestPath"
      ],
      "properties": {
        "modulePath": { "type": ["string", "null"] },
        "solution": { "type": "string", "minLength": 1 },
        "outputDir": { "type": "string", "minLength": 1 },
        "seed": { "type": "string", "minLength": 1 },
        "startFrom": { "type": "integer", "minimum": 1 },
        "runTimeoutMs": { "type": "integer", "minimum": 1 },
        "caseConcurrency": { "type": ["integer", "null"], "minimum": 1 },
        "compiler": { "type": ["string", "null"] },
        "compilerFlags": { "type": "array", "items": { "type": "string" } },
        "ojProfile": { "type": ["string", "null"], "enum": ["auto", "linux", "windows", "none", null] },
        "stackSizeBytes": { "type": ["integer", "null"], "minimum": 1 },
        "manifestPath": { "type": ["string", "null"] }
      }
    },
    "execution": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["runArgs", "executablePath", "fingerprint"],
      "properties": {
        "runArgs": { "type": "array", "minItems": 1, "items": { "type": "string" } },
        "executablePath": { "type": "string", "minLength": 1 },
        "fingerprint": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
      }
    },
    "replay": {
      "type": ["object", "null"],
      "additionalProperties": false,
      "required": ["caseNumber", "caseName", "repeatIndex", "outputDir"],
      "properties": {
        "caseNumber": { "type": "integer", "minimum": 1 },
        "caseName": { "type": "string", "minLength": 1 },
        "repeatIndex": { "type": "integer", "minimum": 0 },
        "outputDir": { "type": "string", "minLength": 1 }
      }
    },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["totalCases", "succeeded", "failed", "durationMs"],
      "properties": {
        "totalCases": { "type": "integer", "minimum": 0 },
        "succeeded": { "type": "integer", "minimum": 0 },
        "failed": { "type": "integer", "minimum": 0 },
        "durationMs": { "type": "integer", "minimum": 0 }
      }
    },
    "cases": {
      "type": "array",
      "items": { "$ref": "#/$defs/case" }
    }
  },
  "$defs": {
    "file": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "sha256", "bytes"],
      "properties": {
        "path": { "type": "string", "minLength": 1 },
        "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "bytes": { "type": "integer", "minimum": 0 },
        "lines": { "type": "integer", "minimum": 0 }
      }
    },
    "validation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status", "durationMs"],
      "properties": {
        "status": { "enum": ["not-run", "passed", "failed"] },
        "durationMs": { "type": "integer", "minimum": 0 },
        "reason": { "type": "string" }
      }
    },
    "error": {
      "type": "object",
      "additionalProperties": false,
      "required": ["phase", "kind", "message"],
      "properties": {
        "phase": {
          "enum": ["config", "materialize", "format", "validate", "write-input", "execution", "write-output", "manifest"]
        },
        "kind": {
          "enum": ["generator", "formatter", "validation", "io", "execution", "timeout", "config"]
        },
        "message": { "type": "string" }
      }
    },
    "case": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "caseId",
        "caseNumber",
        "name",
        "repeatIndex",
        "tags",
        "seed",
        "status",
        "durationMs",
        "phases",
        "validation",
        "input",
        "output",
        "error"
      ],
      "properties": {
        "caseId": { "type": "integer", "minimum": 1 },
        "caseNumber": { "type": "integer", "minimum": 1 },
        "name": { "type": "string", "minLength": 1 },
        "repeatIndex": { "type": "integer", "minimum": 0 },
        "tags": { "type": "array", "items": { "type": "string" } },
        "seed": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "status": { "enum": ["success", "failure"] },
        "durationMs": { "type": "integer", "minimum": 0 },
        "phases": {
          "type": "object",
          "additionalProperties": false,
          "required": ["materializeMs", "formatMs", "validateMs", "writeInputMs", "executionMs", "writeOutputMs"],
          "properties": {
            "materializeMs": { "type": "integer", "minimum": 0 },
            "formatMs": { "type": "integer", "minimum": 0 },
            "validateMs": { "type": "integer", "minimum": 0 },
            "writeInputMs": { "type": "integer", "minimum": 0 },
            "executionMs": { "type": "integer", "minimum": 0 },
            "writeOutputMs": { "type": "integer", "minimum": 0 }
          }
        },
        "validation": { "$ref": "#/$defs/validation" },
        "input": { "anyOf": [{ "$ref": "#/$defs/file" }, { "type": "null" }] },
        "output": { "anyOf": [{ "$ref": "#/$defs/file" }, { "type": "null" }] },
        "error": { "anyOf": [{ "$ref": "#/$defs/error" }, { "type": "null" }] }
      }
    }
  }
}
