{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "CacheSphere Decision Brief",
  "description": "Schema for a compact, citeable decision brief generated from CacheSphere catalog data and selected context packs.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "version",
    "title",
    "summary",
    "question",
    "status",
    "input",
    "recommendation",
    "alternatives",
    "decision",
    "evidenceLinks",
    "markdown"
  ],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "title": {
      "type": "string",
      "minLength": 3
    },
    "summary": {
      "type": "string",
      "minLength": 20
    },
    "question": {
      "type": "string",
      "minLength": 10
    },
    "status": {
      "type": "string",
      "enum": ["draft", "review", "stable"]
    },
    "input": {
      "type": "object",
      "additionalProperties": false,
      "required": ["prompt", "projectType", "sourceMode", "selectedPackIds", "constraints"],
      "properties": {
        "prompt": {
          "type": "string",
          "minLength": 10
        },
        "projectType": {
          "type": "string",
          "minLength": 2
        },
        "sourceMode": {
          "type": "string",
          "enum": ["no-cache", "raw-record", "compact-pack"]
        },
        "selectedPackIds": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "uniqueItems": true
        },
        "constraints": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 3
          },
          "uniqueItems": true
        },
        "candidateLanguages": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "uniqueItems": true
        },
        "forbiddenLanguages": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "uniqueItems": true
        }
      }
    },
    "recommendation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["primaryLanguageId", "rationale", "whyNotDefault", "confidence", "nextChecks"],
      "properties": {
        "primaryLanguageId": {
          "type": "string",
          "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
        },
        "rationale": {
          "type": "string",
          "minLength": 20
        },
        "whyNotDefault": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 3
          },
          "uniqueItems": true
        },
        "confidence": {
          "type": "string",
          "enum": ["low", "medium", "high"]
        },
        "nextChecks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 3
          },
          "uniqueItems": true
        }
      }
    },
    "alternatives": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["languageId", "whyConsidered", "tradeoffs"],
        "properties": {
          "languageId": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "whyConsidered": {
            "type": "string",
            "minLength": 10
          },
          "tradeoffs": {
            "type": "array",
            "minItems": 1,
            "items": {
              "type": "string",
              "minLength": 3
            },
            "uniqueItems": true
          }
        }
      }
    },
    "decision": {
      "type": "object",
      "additionalProperties": false,
      "required": ["chosenPath", "selectedPackIds", "detailLinks"],
      "properties": {
        "chosenPath": {
          "type": "string",
          "minLength": 10
        },
        "selectedPackIds": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "uniqueItems": true
        },
        "detailLinks": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["label", "href"],
            "properties": {
              "label": { "type": "string", "minLength": 2 },
              "href": { "type": "string", "minLength": 3 }
            }
          }
        }
      }
    },
    "clarification": {
      "type": "object",
      "additionalProperties": false,
      "required": ["needed", "questions"],
      "properties": {
        "needed": {
          "type": "boolean"
        },
        "questions": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 3
          },
          "uniqueItems": true
        }
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 3
      },
      "uniqueItems": true
    },
    "evidenceLinks": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["label", "href"],
        "properties": {
          "label": { "type": "string", "minLength": 2 },
          "href": { "type": "string", "minLength": 3 }
        }
      }
    },
    "markdown": {
      "type": "string",
      "minLength": 40
    },
    "notes": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 3
      },
      "uniqueItems": true
    }
  }
}
