{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "altheia_qualitative_study_definition_2.5.1.schema.json",
  "title": "ALTHEIA Qualitative Study Definition 2.5.1",
  "type": "object",
  "required": ["package_type", "schema_version", "module_version", "sector_context", "brand_context", "sector_pack_reference", "brand_pack_reference", "collective_reference", "dimension_assignment_plan", "test_id", "test_name", "test_version", "builder_version", "questions", "quality_check"],
  "properties": {
    "package_type": {"const": "altheia_qualitative_study_definition"},
    "schema_version": {"const": "2.5.1"},
    "module_version": {"const": "2.5.1"},
    "test_version": {"const": "2.5.1"},
    "builder_version": {"const": "altheia_qualitative_study_builder_2.5.1"},
    "sector_context": {"$ref": "#/$defs/sectorIdentity"},
    "brand_context": {"type": "object", "required": ["brand_pack_id", "brand_pack_hash", "sector_pack_id"]},
    "sector_pack_reference": {"$ref": "#/$defs/sectorIdentity"},
    "brand_pack_reference": {"type": "object", "required": ["brand_pack_id", "brand_pack_hash", "sector_pack_id"]},
    "collective_reference": {"type": "object", "required": ["collective_id", "revision", "status", "member_count", "collective_hash"], "properties": {"status": {"const": "research_ready"}, "member_count": {"type": "integer", "minimum": 1}}},
    "dimension_assignment_plan": {"$ref": "#/$defs/assignmentPlan"},
    "test_id": {"type": "string", "minLength": 3},
    "test_name": {"type": "string", "minLength": 3},
    "questions": {"type": "array", "minItems": 1, "maxItems": 25, "items": {"$ref": "#/$defs/question"}},
    "quality_check": {"type": "object", "required": ["status", "errors", "warnings"]}
  },
  "$defs": {
    "hash": {"type": "string", "pattern": "^fnv1a-[a-f0-9]{8}$"},
    "canonicalId": {"type": "string", "minLength": 2, "not": {"pattern": "^D[0-9]{2}$"}},
    "sectorIdentity": {"type": "object", "required": ["sector_pack_id", "semantic_hash", "measurement_hash", "assignment_hash", "sector_pack_hash"], "properties": {"semantic_hash": {"$ref": "#/$defs/hash"}, "measurement_hash": {"$ref": "#/$defs/hash"}, "assignment_hash": {"$ref": "#/$defs/hash"}, "sector_pack_hash": {"$ref": "#/$defs/hash"}}},
    "questionPlan": {"type": "object", "required": ["status", "primary_dimension_ids", "secondary_dimension_ids", "rationale"], "properties": {"status": {"const": "locked"}, "primary_dimension_ids": {"type": "array", "minItems": 1, "uniqueItems": true, "items": {"$ref": "#/$defs/canonicalId"}}, "secondary_dimension_ids": {"type": "array", "uniqueItems": true, "items": {"$ref": "#/$defs/canonicalId"}}, "rationale": {"type": "string"}}},
    "planQuestion": {"allOf": [{"$ref": "#/$defs/questionPlan"}, {"type": "object", "required": ["question_id"], "properties": {"question_id": {"type": "string", "minLength": 1}}}]},
    "assignmentPlan": {"type": "object", "required": ["contract_version", "identity", "status", "semantic_hash", "measurement_hash", "assignment_hash", "questions", "plan_hash"], "properties": {"contract_version": {"const": "altheia_question_dimension_plan_1.0"}, "identity": {"const": "canonical_dimension_id"}, "status": {"const": "locked"}, "semantic_hash": {"$ref": "#/$defs/hash"}, "measurement_hash": {"$ref": "#/$defs/hash"}, "assignment_hash": {"$ref": "#/$defs/hash"}, "questions": {"type": "array", "minItems": 1, "items": {"$ref": "#/$defs/planQuestion"}}, "plan_hash": {"$ref": "#/$defs/hash"}}},
    "question": {"type": "object", "required": ["question_id", "question_order", "question_text", "question_type", "dimension_plan"], "properties": {"question_id": {"type": "string", "minLength": 1}, "question_order": {"type": "integer", "minimum": 1}, "question_text": {"type": "string", "minLength": 3}, "question_type": {"type": "string", "minLength": 2}, "dimension_plan": {"$ref": "#/$defs/questionPlan"}}}
  }
}
