{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://simular.paiml.com/schemas/experiment.schema.json",
  "title": "EDD v2 Experiment Schema",
  "description": "JSON Schema for simular YAML-only experiment definitions",
  "type": "object",
  "required": ["id", "seed", "simulation", "falsification"],
  "additionalProperties": true,
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^[A-Z0-9]+-[A-Z0-9]+-[0-9]+$|^[A-Z0-9]+-[0-9]+$",
      "description": "Unique experiment identifier (e.g., TSP-GRASP-001)"
    },
    "seed": {
      "type": "integer",
      "minimum": 0,
      "description": "Random seed for reproducibility (MANDATORY)"
    },
    "emc_ref": {
      "type": "string",
      "minLength": 1,
      "description": "Reference to Equation Model Card (e.g., optimization/tsp_grasp)"
    },
    "simulation": {
      "type": "object",
      "required": ["type"],
      "additionalProperties": true,
      "properties": {
        "type": {
          "type": "string",
          "minLength": 1,
          "description": "Simulation type (must be supported by core engine)"
        },
        "parameters": {
          "type": "object",
          "additionalProperties": true,
          "description": "Simulation parameters as key-value pairs"
        }
      },
      "not": {
        "anyOf": [
          { "required": ["javascript"] },
          { "required": ["script"] },
          { "required": ["html"] },
          { "required": ["code"] },
          { "required": ["eval"] },
          { "required": ["function"] }
        ]
      }
    },
    "falsification": {
      "type": "object",
      "required": ["criteria"],
      "additionalProperties": false,
      "properties": {
        "criteria": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/falsificationCriterion"
          },
          "description": "Falsification criteria (at least one required)"
        }
      }
    },
    "hypothesis": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "null_hypothesis": {
          "type": "string",
          "description": "Null hypothesis to reject"
        },
        "expected_outcome": {
          "type": "string",
          "enum": ["reject", "fail_to_reject"],
          "description": "Expected outcome of hypothesis test"
        },
        "statistical_test": {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "description": "Type of statistical test"
            },
            "alpha": {
              "type": "number",
              "minimum": 0,
              "maximum": 1,
              "description": "Significance level"
            },
            "power": {
              "type": "number",
              "minimum": 0,
              "maximum": 1,
              "description": "Statistical power"
            }
          }
        }
      }
    }
  },
  "$defs": {
    "falsificationCriterion": {
      "type": "object",
      "required": ["id", "threshold", "condition"],
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Criterion identifier"
        },
        "metric": {
          "type": "string",
          "description": "Metric to evaluate (defaults to id if not specified)"
        },
        "threshold": {
          "type": "number",
          "description": "Threshold value for the criterion"
        },
        "condition": {
          "type": "string",
          "minLength": 1,
          "description": "Condition expression (e.g., 'gap < threshold')"
        },
        "tolerance": {
          "type": "number",
          "minimum": 0,
          "description": "Tolerance for comparison"
        },
        "severity": {
          "type": "string",
          "enum": ["critical", "major", "minor"],
          "default": "major",
          "description": "Severity level of the criterion"
        }
      }
    }
  }
}
