{
  "$schema":"https://json-schema.org/draft/2020-12/schema",
  "$id":"https://brali-lifeos.github.io/contracts/hack.schema.json",
  "title":"Brali Hack",
  "description":"Atomic practical technique that can be reused inside one or more protocols. New records should classify the hack with Domain and Topic, and may additionally attach Methods and Lenses; legacy Life Area and Growth Zone fields remain required during migration for compatibility.",
  "type":"object",
  "additionalProperties":false,
  "required":["schema_version","id","title","summary","action","life_area_slugs","zone_slugs","evidence"],
  "properties":{
    "schema_version":{"const":1},
    "id":{"type":"string","pattern":"^[a-z0-9]+(?:-[a-z0-9]+)*$"},
    "title":{"type":"string","minLength":3},
    "summary":{"type":"string","minLength":10},
    "problem":{"type":"string"},
    "action":{"type":"string","minLength":10},
    "check_in":{"type":"string"},
    "duration":{"type":"string"},
    "review_after":{"type":"string"},
    "stop_or_change_rule":{"type":"string"},
    "life_area_slugs":{"type":"array","minItems":1,"items":{"type":"string"},"uniqueItems":true,"description":"Legacy compatibility classification. Prefer domain_slugs for new integrations."},
    "zone_slugs":{"type":"array","minItems":1,"items":{"type":"string"},"uniqueItems":true,"description":"Legacy Growth Zone compatibility classification. Prefer topic_slugs/method_slugs/lens_slugs for new integrations."},
    "domain_slugs":{"type":"array","items":{"type":"string","pattern":"^[a-z0-9]+(?:-[a-z0-9]+)*$"},"uniqueItems":true,"description":"Broad areas from the Brali knowledge ontology."},
    "topic_slugs":{"type":"array","items":{"type":"string","pattern":"^[a-z0-9]+(?:-[a-z0-9]+)*$"},"uniqueItems":true,"description":"Concrete problems or capabilities from the Brali knowledge ontology."},
    "method_slugs":{"type":"array","items":{"type":"string","pattern":"^[a-z0-9]+(?:-[a-z0-9]+)*$"},"uniqueItems":true,"description":"Named structured approaches used by the hack. Methods do not replace Topics."},
    "lens_slugs":{"type":"array","items":{"type":"string","pattern":"^[a-z0-9]+(?:-[a-z0-9]+)*$"},"uniqueItems":true,"description":"Transferable Brali Lenses used to frame the hack. Lenses are not evidence."},
    "method_tags":{"type":"array","items":{"type":"string"},"uniqueItems":true,"description":"Legacy free-form method tags; structured method_slugs are preferred for ontology-aware records."},
    "keywords":{"type":"array","items":{"type":"string"},"uniqueItems":true},
    "origin":{"type":"string","enum":["legacy","research-derived","editorial","community"]},
    "source_candidate_ids":{"type":"array","items":{"type":"string"},"uniqueItems":true},
    "evidence_decision_ids":{"type":"array","items":{"type":"string"},"uniqueItems":true},
    "risk_flags":{"type":"array","items":{"type":"string","enum":["health","mental-health","financial","legal","safety-critical","clinical","none"]},"uniqueItems":true},
    "evidence":{"$ref":"#/$defs/evidence"}
  },
  "allOf":[
    {
      "if":{"properties":{"origin":{"const":"research-derived"}},"required":["origin"]},
      "then":{
        "required":["source_candidate_ids","evidence_decision_ids"],
        "properties":{
          "source_candidate_ids":{"minItems":1},
          "evidence_decision_ids":{"minItems":1},
          "evidence":{"properties":{"sources":{"minItems":1}},"required":["sources"]}
        }
      }
    }
  ],
  "$defs":{
    "source":{
      "type":"object","additionalProperties":false,
      "required":["url","title","source_type","claim_scope"],
      "properties":{
        "url":{"type":"string","format":"uri"},
        "title":{"type":"string","minLength":3},
        "doi":{"type":["string","null"]},
        "source_type":{"type":"string","enum":["primary-study","systematic-review","meta-analysis","guideline","expert-consensus","other"]},
        "publisher":{"type":"string"},
        "published_date":{"type":["string","null"]},
        "accessed_at":{"type":["string","null"],"format":"date"},
        "citation_text":{"type":"string"},
        "claim_scope":{"type":"string","minLength":5}
      }
    },
    "evidence":{
      "type":"object","additionalProperties":false,"required":["state"],
      "properties":{
        "state":{"type":"string","enum":["reviewed","practical","pending-review","restricted"]},
        "reviewed_at":{"type":["string","null"],"format":"date"},
        "reviewed_by":{"type":["string","null"]},
        "notes":{"type":"string"},
        "limitations":{"type":"array","items":{"type":"string"}},
        "sources":{"type":"array","items":{"$ref":"#/$defs/source"}}
      },
      "allOf":[
        {
          "if":{"properties":{"state":{"const":"reviewed"}},"required":["state"]},
          "then":{"required":["reviewed_at","reviewed_by","sources"],"properties":{"sources":{"minItems":1}}}
        }
      ]
    }
  }
}
