{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Pre-execution machine-learning modelling plan",
  "type": "object",
  "properties": {
    "schema_version": {
      "const": 1
    },
    "plan_id": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9_-]{0,63}$"
    },
    "mode": {
      "enum": [
        "build",
        "reproduce"
      ]
    },
    "created_at": {
      "type": "string"
    },
    "question": {
      "type": "string",
      "minLength": 8,
      "maxLength": 4000
    },
    "data": {
      "type": "object",
      "properties": {
        "asset_id": {
          "type": "string",
          "minLength": 3
        },
        "input_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "dictionary_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "development_profile_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "required": [
        "asset_id",
        "input_sha256",
        "dictionary_sha256",
        "development_profile_sha256"
      ],
      "additionalProperties": false
    },
    "task": {
      "type": "object"
    },
    "decisions": {
      "type": "object",
      "properties": {
        "target": {
          "$ref": "#/$defs/decision"
        },
        "variables": {
          "$ref": "#/$defs/decision"
        },
        "parameters": {
          "$ref": "#/$defs/decision"
        },
        "split": {
          "$ref": "#/$defs/decision"
        },
        "preprocessing": {
          "$ref": "#/$defs/decision"
        },
        "evaluation": {
          "$ref": "#/$defs/decision"
        },
        "interpretation": {
          "$ref": "#/$defs/decision"
        }
      },
      "required": [
        "target",
        "variables",
        "parameters",
        "split",
        "preprocessing",
        "evaluation",
        "interpretation"
      ],
      "additionalProperties": false
    },
    "variables": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/variable"
      },
      "minItems": 1,
      "maxItems": 64
    },
    "parameter_space": {
      "type": "object",
      "minProperties": 1,
      "additionalProperties": {
        "type": "object",
        "minProperties": 0,
        "additionalProperties": {
          "type": "array",
          "minItems": 1,
          "maxItems": 30,
          "uniqueItems": true,
          "items": {
            "type": [
              "number",
              "boolean",
              "string"
            ]
          }
        }
      }
    },
    "issues": {
      "type": "array",
      "maxItems": 50,
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "blocking": {
            "type": "boolean"
          },
          "description": {
            "type": "string",
            "minLength": 8,
            "maxLength": 4000
          }
        },
        "required": [
          "id",
          "blocking",
          "description"
        ],
        "additionalProperties": false
      }
    },
    "review_policy": {
      "const": "human_by_default"
    }
  },
  "required": [
    "schema_version",
    "plan_id",
    "mode",
    "created_at",
    "question",
    "data",
    "task",
    "decisions",
    "variables",
    "parameter_space",
    "issues",
    "review_policy"
  ],
  "additionalProperties": false,
  "$defs": {
    "decision": {
      "type": "object",
      "properties": {
        "choice": {
          "type": "string",
          "minLength": 8,
          "maxLength": 4000
        },
        "reason": {
          "type": "string",
          "minLength": 8,
          "maxLength": 4000
        },
        "uncertainty": {
          "type": "string",
          "minLength": 8,
          "maxLength": 4000
        },
        "evidence": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 3,
            "maxLength": 1000
          },
          "minItems": 1,
          "maxItems": 20
        },
        "alternatives": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 3,
            "maxLength": 1000
          },
          "minItems": 1,
          "maxItems": 20
        }
      },
      "required": [
        "choice",
        "reason",
        "evidence",
        "alternatives",
        "uncertainty"
      ],
      "additionalProperties": false
    },
    "variable": {
      "type": "object",
      "properties": {
        "column": {
          "type": "string",
          "minLength": 1
        },
        "physical_meaning": {
          "type": "string",
          "minLength": 8,
          "maxLength": 4000
        },
        "reason": {
          "type": "string",
          "minLength": 8,
          "maxLength": 4000
        },
        "uncertainty": {
          "type": "string",
          "minLength": 8,
          "maxLength": 4000
        },
        "unit": {
          "type": "string",
          "minLength": 1
        },
        "role": {
          "enum": [
            "predictor",
            "adjustment"
          ]
        },
        "evidence": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 3,
            "maxLength": 1000
          },
          "minItems": 1,
          "maxItems": 20
        }
      },
      "required": [
        "column",
        "physical_meaning",
        "unit",
        "role",
        "reason",
        "evidence",
        "uncertainty"
      ],
      "additionalProperties": false
    }
  }
}
