{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://quantkit.co/data/prop-rules/prop-rules.schema.json",
  "title": "QuantKit prop-rules dataset v1",
  "description": "Every rule is a sourced field. status=verified needs a non-null value, an https source_url (one of the program's sources) and an as_of not later than meta.as_of. status=unknown, not_applicable and conflicting have value null (conflicting also needs a note). The repository validator (scripts/validate-prop-rules.mjs) enforces these rules and the enum memberships below.",
  "type": "object",
  "required": ["schema_version", "dataset_id", "dataset_version", "meta", "firms", "changes"],
  "properties": {
    "schema_version": {"type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+$"},
    "dataset_id": {"const": "prop-rules"},
    "dataset_version": {"type": "string"},
    "meta": {"type": "object", "required": ["as_of", "license", "canonical_url"], "properties": {"as_of": {"$ref": "#/$defs/date"}, "license": {"type": "string"}, "canonical_url": {"type": "string", "format": "uri"}, "notes": {"type": "array", "items": {"type": "string"}}}},
    "firms": {"type": "array", "minItems": 1, "items": {"type": "object", "required": ["id", "name", "programs"], "properties": {"id": {"type": "string"}, "name": {"type": "string"}, "programs": {"type": "array", "items": {"$ref": "#/$defs/program"}}}}},
    "changes": {"type": "array", "items": {"type": "object", "required": ["id", "date", "program_id", "summary", "field_path"], "properties": {"id": {"type": "string"}, "date": {"$ref": "#/$defs/date"}, "program_id": {"type": "string"}, "summary": {"type": "string"}, "field_path": {"type": ["string", "null"], "description": "Dot path of the changed field, or null for a narrative entry."}}}}
  },
  "$defs": {
    "date": {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$"},
    "sourced": {
      "type": "object", "required": ["value", "status", "as_of"],
      "properties": {
        "value": {}, "unit": {"type": "string"}, "status": {"enum": ["verified", "unknown", "not_applicable", "conflicting"]},
        "as_of": {"$ref": "#/$defs/date"}, "source_url": {"type": "string", "pattern": "^https://"}, "source_scope": {"enum": ["page", "program"]}, "note": {"type": "string"}
      },
      "allOf": [
        {"if": {"properties": {"status": {"const": "verified"}}}, "then": {"required": ["source_url", "source_scope"], "properties": {"value": {"not": {"type": "null"}}}}},
        {"if": {"properties": {"status": {"enum": ["unknown", "not_applicable", "conflicting"]}}}, "then": {"properties": {"value": {"type": "null"}}}},
        {"if": {"properties": {"status": {"const": "conflicting"}}}, "then": {"required": ["note"]}}
      ]
    },
    "percent": {"description": "number, or {tiers:[{min,max,pct}]} chosen by account size in USD, or {stages:{phase_1|phase_2|step_1..|funded: number|null}} chosen by stage", "oneOf": [{"type": "number"}, {"type": "null"}, {"type": "object", "required": ["tiers"], "properties": {"tiers": {"type": "array", "items": {"type": "object", "required": ["min", "max", "pct"]}}}}, {"type": "object", "required": ["stages"]}]},
    "program": {
      "type": "object",
      "required": ["id", "firm_id", "firm", "label", "kind", "daily_loss", "max_drawdown", "consistency", "sources", "change_ids"],
      "properties": {
        "id": {"type": "string", "pattern": "^[a-z0-9-]+$"}, "kind": {"enum": ["one_step", "two_step", "multi_step", "instant", "other"]},
        "daily_loss": {"type": "object", "description": "limit_pct ($defs/percent), limit_base: initial_balance|reference|unknown, reference: balance_start_of_day|equity_start_of_day|max_balance_equity_start_of_day|initial_balance|unknown, measured_on: equity|balance|equity_or_balance|unknown, reset_time, basis_text (all sourced fields)"},
        "max_drawdown": {"type": "object", "description": "limit_pct, type: static|trailing_eod|trailing_closed_balance_lock|..., measured_on, lock_at_initial (bool), detail"},
        "consistency": {"type": "object", "description": "rule_type: none|best_day_pct_of_total_profit|best_day_pct_of_target|other, limit_pct, denominator: net_total_profit|sum_positive_days|profit_target|unknown, applies_to, breach_effect, detail"},
        "sources": {"type": "array", "items": {"type": "string", "pattern": "^https://"}}, "change_ids": {"type": "array", "items": {"type": "string"}}, "unverified_notes": {"type": "array", "items": {"type": "string"}}
      }
    }
  }
}
