{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tattvabodha.com/schemas/practice-core-v1.0.0.schema.json",
  "title": "Tattvabodha Practice Core",
  "description": "A complete, resolved, presentation-independent practice record for Practice Core Specification v1.0.0.",
  "$ref": "#/$defs/PracticeCore",
  "$defs": {
    "Identifier": {
      "type": "string",
      "minLength": 1,
      "pattern": "^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$",
      "description": "Stable canonical library identifier."
    },
    "SkillIds": {
      "type": "array",
      "items": { "$ref": "#/$defs/Identifier" },
      "uniqueItems": true,
      "description": "Canonical skill references in first-occurrence method order."
    },
    "PracticeStep": {
      "type": "object",
      "required": ["instruction"],
      "properties": {
        "action": { "$ref": "#/$defs/Identifier", "description": "Canonical action identifier; actions are not necessarily skills." },
        "skills": { "$ref": "#/$defs/SkillIds" },
        "instruction": { "type": "string", "minLength": 1 },
        "when": { "$ref": "#/$defs/Identifier", "description": "Condition that makes this response relevant." },
        "with": { "$ref": "#/$defs/Identifier", "description": "Canonical response method identifier." }
      },
      "anyOf": [
        { "required": ["action"] },
        { "required": ["with"] },
        { "properties": { "skills": { "minItems": 1 } }, "required": ["skills"] }
      ],
      "additionalProperties": false
    },
    "ConditionalResponse": {
      "allOf": [
        { "$ref": "#/$defs/PracticeStep" },
        { "required": ["when"] }
      ]
    },
    "PracticeMethod": {
      "type": "object",
      "required": ["prepare", "engage", "respond", "close"],
      "properties": {
        "prepare": { "type": "array", "items": { "$ref": "#/$defs/PracticeStep" } },
        "engage": { "type": "array", "items": { "$ref": "#/$defs/PracticeStep" } },
        "respond": { "type": "array", "items": { "$ref": "#/$defs/ConditionalResponse" } },
        "close": { "type": "array", "items": { "$ref": "#/$defs/PracticeStep" } }
      },
      "additionalProperties": false
    },
    "PracticeCore": {
      "type": "object",
      "required": ["id", "name", "essence", "intention", "skills", "cultivates", "fruits", "method"],
      "properties": {
        "id": { "$ref": "#/$defs/Identifier" },
        "name": { "type": "string", "minLength": 1 },
        "essence": { "type": "string", "minLength": 1 },
        "intention": { "$ref": "#/$defs/Identifier" },
        "object": { "$ref": "#/$defs/Identifier", "description": "Optional default object of practice." },
        "skills": { "$ref": "#/$defs/SkillIds" },
        "cultivates": { "type": "array", "items": { "$ref": "#/$defs/Identifier" }, "uniqueItems": true },
        "fruits": { "type": "array", "items": { "$ref": "#/$defs/Identifier" }, "uniqueItems": true },
        "method": { "$ref": "#/$defs/PracticeMethod" }
      },
      "additionalProperties": false
    },
    "PracticeMetadata": {
      "type": "object",
      "required": ["practiceId"],
      "properties": {
        "practiceId": { "$ref": "#/$defs/Identifier" },
        "defaultExperienceId": { "$ref": "#/$defs/Identifier", "description": "Canonical default Experience for this practice; should agree with its has_default_experience relationship." },
        "alternateNames": { "type": "array", "items": { "type": "string" } },
        "traditions": { "type": "array", "items": { "$ref": "#/$defs/Identifier" } },
        "lineages": { "type": "array", "items": { "$ref": "#/$defs/Identifier" } },
        "historicalOrigins": { "type": "array", "items": { "type": "string" } },
        "sources": { "type": "array", "items": { "$ref": "#/$defs/Identifier" } },
        "relatedPractices": { "type": "array", "items": { "$ref": "#/$defs/Identifier" } },
        "relatedConcepts": { "type": "array", "items": { "$ref": "#/$defs/Identifier" } },
        "interpretations": { "type": "array", "items": { "type": "object" } }
      },
      "additionalProperties": true
    },
    "PracticePresentation": {
      "type": "object",
      "required": ["practiceId"],
      "properties": {
        "practiceId": { "$ref": "#/$defs/Identifier" },
        "symbol": { "type": "string" },
        "icon": { "type": "string" },
        "layout": { "type": "string" },
        "accent": { "type": "string" },
        "homeBase": { "type": "object" },
        "arising": { "type": "object" },
        "relationship": { "type": "object" }
      },
      "additionalProperties": true
    }
  }
}
