{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://machinetradecraft.com/downloads/machine-tradecraft-representation-policy-schema-v1.json",
  "title": "Machine Tradecraft Representation Policy Export",
  "description": "Schema version 1.0.0 for deterministic, non-scoring representation-policy exports generated by MachineTradecraft.com.",
  "type": "object",
  "required": ["generated_by", "site_version", "release_id", "policy"],
  "additionalProperties": false,
  "properties": {
    "generated_by": {"const": "MachineTradecraft.com Representation Policy Builder"},
    "site_version": {"type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"},
    "release_id": {"type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}-[a-z0-9-]+$"},
    "policy": {"$ref": "#/$defs/policy"}
  },
  "$defs": {
    "status": {
      "type": "object",
      "required": ["id", "label", "description"],
      "additionalProperties": false,
      "properties": {
        "id": {"enum": ["required", "recommended", "context-dependent", "prohibited", "externally-verified"]},
        "label": {"type": "string", "minLength": 3, "maxLength": 40},
        "description": {"type": "string", "minLength": 20, "maxLength": 500}
      }
    },
    "laboratory": {
      "type": "object",
      "required": ["slug", "path", "actions"],
      "additionalProperties": false,
      "properties": {
        "slug": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "path": {"type": "string", "pattern": "^/labs/.+/$"},
        "actions": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["id", "label"],
            "additionalProperties": false,
            "properties": {
              "id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
              "label": {"type": "string", "minLength": 3, "maxLength": 120}
            }
          }
        }
      }
    },
    "topic": {
      "type": "object",
      "required": ["topic_id", "title", "guide", "report", "laboratory"],
      "additionalProperties": false,
      "properties": {
        "topic_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "title": {"type": "string", "minLength": 3, "maxLength": 180},
        "guide": {"type": "string", "pattern": "^/.+/$"},
        "report": {"type": "string", "pattern": "^/research/.+/$"},
        "laboratory": {"$ref": "#/$defs/laboratory"}
      }
    },
    "fixture": {
      "type": "object",
      "required": ["case_id", "case_title", "fixture", "bytes", "sha256", "download_url", "laboratory"],
      "additionalProperties": false,
      "properties": {
        "case_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "case_title": {"type": "string", "minLength": 3, "maxLength": 180},
        "fixture": {"type": "string", "minLength": 3, "maxLength": 180},
        "bytes": {"type": "integer", "minimum": 1},
        "sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"},
        "download_url": {"type": "string", "pattern": "^/downloads/.+"},
        "laboratory": {
          "type": "object",
          "required": ["slug", "path", "action"],
          "additionalProperties": false,
          "properties": {
            "slug": {"type": "string", "pattern": "^[a-z0-9-]+$"},
            "path": {"type": "string", "pattern": "^/labs/.+/$"},
            "action": {"type": "string", "pattern": "^[a-z0-9-]+$"}
          }
        }
      }
    },
    "resources": {
      "type": "object",
      "required": ["topics", "fixtures", "glossary", "casebook", "analyst_handoff"],
      "additionalProperties": false,
      "properties": {
        "topics": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/topic"}},
        "fixtures": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/fixture"}},
        "glossary": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "required": ["term_id", "url"],
            "additionalProperties": false,
            "properties": {
              "term_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
              "url": {"type": "string", "pattern": "^/machine-tradecraft-glossary/#.+"}
            }
          }
        },
        "casebook": {"const": "/representation-casebook/"},
        "analyst_handoff": {"const": "/representation-casebook/#analyst-handoff"}
      }
    },
    "decision": {
      "type": "object",
      "required": ["decision_id", "label", "status", "rationale", "checklist", "test"],
      "additionalProperties": false,
      "properties": {
        "decision_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "label": {"type": "string", "minLength": 3, "maxLength": 120},
        "status": {"$ref": "#/$defs/status"},
        "rationale": {"type": "string", "minLength": 40, "maxLength": 3000},
        "checklist": {"type": "string", "minLength": 20, "maxLength": 1200},
        "test": {"type": "string", "minLength": 20, "maxLength": 1200}
      }
    },
    "verification": {
      "type": "object",
      "required": ["requirement_id", "profile_id", "profile_label", "authority", "requirement"],
      "additionalProperties": false,
      "properties": {
        "requirement_id": {"type": "string", "pattern": "^V-[0-9]{2}-[0-9]{2}$"},
        "profile_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "profile_label": {"type": "string", "minLength": 3, "maxLength": 120},
        "authority": {"enum": ["browser", "parser", "cryptographic-service", "model", "registry", "dns", "organizational-owner", "other"]},
        "requirement": {"type": "string", "minLength": 20, "maxLength": 1200}
      }
    },
    "profile": {
      "type": "object",
      "required": ["id", "label", "category", "description", "focus", "do_not_apply", "resources", "decisions", "verification_requirements"],
      "additionalProperties": false,
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "label": {"type": "string", "minLength": 3, "maxLength": 120},
        "category": {"type": "string", "minLength": 3, "maxLength": 120},
        "description": {"type": "string", "minLength": 20, "maxLength": 1000},
        "focus": {"type": "string", "minLength": 20, "maxLength": 1600},
        "do_not_apply": {"type": "string", "minLength": 20, "maxLength": 1600},
        "resources": {"$ref": "#/$defs/resources"},
        "decisions": {"type": "array", "minItems": 15, "maxItems": 15, "items": {"$ref": "#/$defs/decision"}},
        "verification_requirements": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/verification"}}
      }
    },
    "matrixProfile": {
      "type": "object",
      "required": ["profile_id", "profile_label", "status"],
      "additionalProperties": false,
      "properties": {
        "profile_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "profile_label": {"type": "string", "minLength": 3, "maxLength": 120},
        "status": {"$ref": "#/$defs/status"}
      }
    },
    "matrixDecision": {
      "type": "object",
      "required": ["decision_id", "label", "description", "profiles"],
      "additionalProperties": false,
      "properties": {
        "decision_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "label": {"type": "string", "minLength": 3, "maxLength": 120},
        "description": {"type": "string", "minLength": 20, "maxLength": 1000},
        "profiles": {"type": "array", "minItems": 1, "maxItems": 5, "items": {"$ref": "#/$defs/matrixProfile"}}
      }
    },
    "check": {
      "type": "object",
      "required": ["check_id", "profile_id", "profile_label", "decision_id", "decision_label", "status", "task"],
      "additionalProperties": false,
      "properties": {
        "check_id": {"type": "string", "pattern": "^P[0-9]{2}-D[0-9]{2}$"},
        "profile_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "profile_label": {"type": "string", "minLength": 3, "maxLength": 120},
        "decision_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "decision_label": {"type": "string", "minLength": 3, "maxLength": 120},
        "status": {"$ref": "#/$defs/status"},
        "task": {"type": "string", "minLength": 20, "maxLength": 1200}
      }
    },
    "test": {
      "type": "object",
      "required": ["test_id", "profile_id", "profile_label", "decision_id", "decision_label", "status", "method", "expected_result"],
      "additionalProperties": false,
      "properties": {
        "test_id": {"type": "string", "pattern": "^T-P[0-9]{2}-D[0-9]{2}$"},
        "profile_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "profile_label": {"type": "string", "minLength": 3, "maxLength": 120},
        "decision_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
        "decision_label": {"type": "string", "minLength": 3, "maxLength": 120},
        "status": {"$ref": "#/$defs/status"},
        "method": {"type": "string", "minLength": 20, "maxLength": 1200},
        "expected_result": {"type": "string", "minLength": 20, "maxLength": 1200}
      }
    },
    "policy": {
      "type": "object",
      "required": ["schema_version", "policy_schema_version", "site_version", "release_id", "profile_count", "profiles", "decision_matrix", "profile_conflicts", "control_checklist", "test_plan", "external_verification_requirements", "schema_url", "non_conclusions", "policy_id", "policy_sha256"],
      "additionalProperties": false,
      "properties": {
        "schema_version": {"const": 1},
        "policy_schema_version": {"const": "1.0.0"},
        "site_version": {"type": "string", "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"},
        "release_id": {"type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}-[a-z0-9-]+$"},
        "profile_count": {"type": "integer", "minimum": 1, "maximum": 5},
        "profiles": {"type": "array", "minItems": 1, "maxItems": 5, "items": {"$ref": "#/$defs/profile"}},
        "decision_matrix": {"type": "array", "minItems": 15, "maxItems": 15, "items": {"$ref": "#/$defs/matrixDecision"}},
        "profile_conflicts": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["decision_id", "decision_label", "statuses", "explanation"],
            "additionalProperties": false,
            "properties": {
              "decision_id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
              "decision_label": {"type": "string", "minLength": 3, "maxLength": 120},
              "statuses": {"type": "array", "minItems": 2, "uniqueItems": true, "items": {"enum": ["required", "recommended", "context-dependent", "prohibited", "externally-verified"]}},
              "explanation": {"type": "string", "minLength": 20, "maxLength": 500}
            }
          }
        },
        "control_checklist": {"type": "array", "minItems": 15, "maxItems": 75, "items": {"$ref": "#/$defs/check"}},
        "test_plan": {"type": "array", "minItems": 15, "maxItems": 75, "items": {"$ref": "#/$defs/test"}},
        "external_verification_requirements": {"type": "array", "minItems": 1, "maxItems": 20, "items": {"$ref": "#/$defs/verification"}},
        "schema_url": {"const": "/downloads/machine-tradecraft-representation-policy-schema-v1.json"},
        "non_conclusions": {"type": "array", "minItems": 4, "maxItems": 10, "items": {"type": "string", "minLength": 20, "maxLength": 600}},
        "policy_id": {"type": "string", "pattern": "^[A-F0-9]{12}$"},
        "policy_sha256": {"type": "string", "pattern": "^[a-f0-9]{64}$"}
      }
    }
  }
}
