{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://aisa.ablera.com/contracts/module-manifest.schema.json",
  "title": "Module declaration v1",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "module_id",
    "name",
    "case_module",
    "kind",
    "root_profile",
    "memory_root",
    "profiles",
    "entry_stage",
    "stages",
    "edges",
    "eval_sets"
  ],
  "properties": {
    "schema_version": {
      "const": 1
    },
    "module_id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_-]+$"
    },
    "name": {
      "type": "string"
    },
    "case_module": {
      "enum": [
        "support",
        "configuration",
        "source"
      ]
    },
    "kind": {
      "enum": [
        "root",
        "working",
        "embedded"
      ]
    },
    "root_profile": {
      "type": "string"
    },
    "memory_root": {
      "type": "string"
    },
    "profiles": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "execution_kind",
          "owns"
        ],
        "properties": {
          "key": {
            "type": "string"
          },
          "execution_kind": {
            "enum": [
              "llm",
              "deterministic"
            ]
          },
          "owns": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "uniqueItems": true
          }
        }
      }
    },
    "entry_stage": {
      "type": "string"
    },
    "stages": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "profile",
          "consumes",
          "produces",
          "gates",
          "done"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "profile": {
            "type": "string"
          },
          "consumes": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "uniqueItems": true
          },
          "produces": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "uniqueItems": true
          },
          "gates": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "kind",
                "when"
              ],
              "properties": {
                "kind": {
                  "enum": [
                    "H1",
                    "H2",
                    "H3",
                    "H4",
                    "H5",
                    "H6",
                    "H7",
                    "Hd",
                    "HW-approve",
                    "HW-instance",
                    "HW-shared",
                    "HW-irreversible",
                    "HW-ddl",
                    "H5-SIM",
                    "H5-send",
                    "CG-11",
                    "publish"
                  ]
                },
                "when": {
                  "enum": [
                    "entry",
                    "plan_ready",
                    "result_ready",
                    "before_execution",
                    "on_problem",
                    "on_handover"
                  ]
                }
              }
            }
          },
          "done": {
            "type": "string",
            "minLength": 1
          },
          "profile_variants": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        }
      }
    },
    "edges": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "from",
          "to",
          "on",
          "kind"
        ],
        "properties": {
          "from": {
            "type": "string"
          },
          "to": {
            "type": "string"
          },
          "on": {
            "type": "string"
          },
          "kind": {
            "enum": [
              "dependency",
              "rework",
              "asynchronous"
            ]
          }
        }
      }
    },
    "eval_sets": {
      "type": "array",
      "items": {
        "type": "string"
      },
      "uniqueItems": true,
      "minItems": 1
    }
  }
}
