{
  "$schema":"https://json-schema.org/draft/2020-12/schema",
  "$id":"https://brali-lifeos.github.io/contracts/protocol.schema.json",
  "title":"Brali Protocol",
  "description":"Executable experiment or sequence that combines one or more practical actions, usually referencing Brali hacks. New records should classify the protocol 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","problem","steps","check_in","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},
    "problem":{"type":"string","minLength":10},
    "protocol_type":{"type":"string","enum":["single-action","sequence","personal-experiment"]},
    "steps":{"type":"array","minItems":1,"items":{"type":"object","additionalProperties":false,"required":["instruction"],"properties":{"order":{"type":"integer","minimum":1},"hack_id":{"type":["string","null"]},"instruction":{"type":"string","minLength":5},"when":{"type":"string"},"duration":{"type":"string"}}}},
    "check_in":{"type":"string","minLength":5},
    "success_signal":{"type":"string"},
    "review_after":{"type":"string"},
    "stop_or_change_rule":{"type":"string"},
    "safety_notes":{"type":"array","items":{"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 protocol. 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 protocol. 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."},
    "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"}},
        "source_hack_ids":{"type":"array","items":{"type":"string"},"uniqueItems":true},
        "evidence_decision_ids":{"type":"array","items":{"type":"string"},"uniqueItems":true},
        "sources":{
          "type":"array",
          "items":{
            "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}
            }
          }
        }
      },
      "allOf":[
        {
          "if":{"properties":{"state":{"const":"reviewed"}},"required":["state"]},
          "then":{"required":["reviewed_at","reviewed_by","sources"],"properties":{"sources":{"minItems":1}}}
        }
      ]
    }
  }
}
