{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hedgefund.wiki/api/schema.json",
  "title": "hedgefund.wiki Knowledge API Schemas",
  "description": "JSON Schema 2020-12 type definitions for every entity in the hedgefund.wiki API.",
  "definitions": {
    "Slug": {
      "type": "string",
      "pattern": "^[a-z0-9]+(-[a-z0-9]+)*$",
      "description": "Stable kebab-case ASCII identifier (entity slug)."
    },
    "ParamId": {
      "type": "string",
      "pattern": "^[A-Za-z_][A-Za-z0-9_]*$",
      "description": "Variable / parameter identifier, e.g. for calculator inputs and outputs. Snake_case or single ASCII letter; must be valid in most programming languages."
    },
    "EntityType": {
      "type": "string",
      "enum": [
        "term",
        "category",
        "strategy",
        "formula",
        "structure",
        "risk-concept",
        "calculator",
        "regulation",
        "event",
        "person",
        "chunk"
      ]
    },
    "Reference": {
      "type": "object",
      "required": ["type", "id"],
      "properties": {
        "type": { "$ref": "#/definitions/EntityType" },
        "id": { "$ref": "#/definitions/Slug" },
        "label": {
          "type": "string",
          "description": "Optional human-readable label — denormalized convenience for UIs that don't dereference."
        }
      },
      "additionalProperties": false
    },
    "Source": {
      "type": "object",
      "required": ["title", "url"],
      "properties": {
        "title": { "type": "string" },
        "url": { "type": "string", "format": "uri" },
        "publisher": { "type": "string" },
        "type": {
          "type": "string",
          "enum": ["academic", "regulatory", "industry", "news", "primary-document", "textbook", "encyclopedia"]
        },
        "accessed": { "type": "string", "format": "date" },
        "license": { "type": "string", "description": "SPDX identifier or URL." }
      }
    },
    "DifficultyLevel": {
      "type": "string",
      "enum": ["intro", "intermediate", "advanced", "expert"]
    },
    "Term": {
      "type": "object",
      "required": ["id", "name", "category", "definition", "level"],
      "properties": {
        "id": { "$ref": "#/definitions/Slug" },
        "name": { "type": "string" },
        "abbreviation": { "type": "string" },
        "aliases": { "type": "array", "items": { "type": "string" } },
        "plural": { "type": "string" },
        "category": { "$ref": "#/definitions/Slug" },
        "subcategory": { "type": "string" },
        "level": { "$ref": "#/definitions/DifficultyLevel" },
        "summary": {
          "type": "string",
          "description": "≤ 280 character one-sentence definition. Self-contained.",
          "maxLength": 320
        },
        "definition": {
          "type": "string",
          "description": "Full prose definition, ≥ 1 paragraph."
        },
        "in_practice": { "type": "string", "description": "How it is actually used on a trading desk / in a fund." },
        "intuition": { "type": "string", "description": "Plain-language mental model." },
        "formula_id": { "$ref": "#/definitions/Slug", "description": "If a single canonical formula defines this term." },
        "example": {
          "type": "object",
          "properties": {
            "scenario": { "type": "string" },
            "computation": { "type": "string" },
            "result": { "type": "string" }
          }
        },
        "common_pitfalls": { "type": "array", "items": { "type": "string" } },
        "see_also": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "regulatory_context": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "first_use": {
          "type": "object",
          "properties": {
            "year": { "type": "integer" },
            "context": { "type": "string" }
          }
        },
        "sources": { "type": "array", "items": { "$ref": "#/definitions/Source" } },
        "tags": { "type": "array", "items": { "type": "string" } },
        "updated": { "type": "string", "format": "date" }
      }
    },
    "Category": {
      "type": "object",
      "required": ["id", "name", "description"],
      "properties": {
        "id": { "$ref": "#/definitions/Slug" },
        "name": { "type": "string" },
        "description": { "type": "string" },
        "parent": { "$ref": "#/definitions/Slug" },
        "term_count": { "type": "integer" },
        "key_terms": { "type": "array", "items": { "$ref": "#/definitions/Slug" } },
        "see_also": { "type": "array", "items": { "$ref": "#/definitions/Reference" } }
      }
    },
    "Strategy": {
      "type": "object",
      "required": ["id", "name", "family", "summary", "mechanism"],
      "properties": {
        "id": { "$ref": "#/definitions/Slug" },
        "name": { "type": "string" },
        "family": {
          "type": "string",
          "enum": [
            "equity-hedge",
            "event-driven",
            "global-macro",
            "relative-value",
            "managed-futures",
            "credit",
            "quantitative",
            "multi-strategy",
            "digital-assets"
          ]
        },
        "summary": { "type": "string", "maxLength": 320 },
        "mechanism": { "type": "string", "description": "How the strategy actually generates P&L." },
        "return_drivers": { "type": "array", "items": { "type": "string" } },
        "typical_instruments": { "type": "array", "items": { "type": "string" } },
        "typical_holding_period": { "type": "string" },
        "leverage_typical": {
          "type": "object",
          "properties": {
            "gross_low": { "type": "number" },
            "gross_high": { "type": "number" },
            "net_low": { "type": "number" },
            "net_high": { "type": "number" }
          }
        },
        "typical_sharpe": {
          "type": "object",
          "properties": { "low": { "type": "number" }, "high": { "type": "number" } }
        },
        "capacity_usd": {
          "type": "object",
          "properties": {
            "single_fund_billion_low": { "type": "number" },
            "single_fund_billion_high": { "type": "number" },
            "industry_billion": { "type": "number" }
          }
        },
        "risk_profile": { "type": "object" },
        "correlation_to_sp500_typical": {
          "type": "object",
          "properties": { "low": { "type": "number" }, "high": { "type": "number" } }
        },
        "best_environment": { "type": "string" },
        "worst_environment": { "type": "string" },
        "famous_practitioners": { "type": "array", "items": { "type": "string" } },
        "notable_blowups": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "related_terms": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "related_formulas": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "regulations": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "history": { "type": "string" },
        "sources": { "type": "array", "items": { "$ref": "#/definitions/Source" } },
        "tags": { "type": "array", "items": { "type": "string" } }
      }
    },
    "Formula": {
      "type": "object",
      "required": ["id", "name", "latex", "plain_text", "variables"],
      "properties": {
        "id": { "$ref": "#/definitions/Slug" },
        "name": { "type": "string" },
        "category": { "$ref": "#/definitions/Slug" },
        "summary": { "type": "string" },
        "latex": { "type": "string", "description": "LaTeX source, no surrounding $$." },
        "plain_text": { "type": "string", "description": "ASCII representation safe for terminals." },
        "variables": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["symbol", "name"],
            "properties": {
              "symbol": { "type": "string" },
              "name": { "type": "string" },
              "description": { "type": "string" },
              "unit": { "type": "string" },
              "typical_range": { "type": "string" }
            }
          }
        },
        "intuition": { "type": "string" },
        "derivation": { "type": "string" },
        "assumptions": { "type": "array", "items": { "type": "string" } },
        "edge_cases": { "type": "array", "items": { "type": "string" } },
        "worked_example": {
          "type": "object",
          "properties": {
            "given": { "type": "object" },
            "steps": { "type": "array", "items": { "type": "string" } },
            "result": { "type": "string" }
          }
        },
        "related_terms": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "see_also": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "first_published": { "type": "object", "properties": { "year": { "type": "integer" }, "by": { "type": "string" } } },
        "sources": { "type": "array", "items": { "$ref": "#/definitions/Source" } }
      }
    },
    "Structure": {
      "type": "object",
      "required": ["id", "name", "summary", "purpose"],
      "properties": {
        "id": { "$ref": "#/definitions/Slug" },
        "name": { "type": "string" },
        "summary": { "type": "string" },
        "purpose": { "type": "string" },
        "mechanics": { "type": "string" },
        "tax_treatment": { "type": "string" },
        "investor_eligibility": { "type": "string" },
        "common_jurisdictions": { "type": "array", "items": { "type": "string" } },
        "advantages": { "type": "array", "items": { "type": "string" } },
        "disadvantages": { "type": "array", "items": { "type": "string" } },
        "regulations": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "see_also": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "sources": { "type": "array", "items": { "$ref": "#/definitions/Source" } }
      }
    },
    "Calculator": {
      "type": "object",
      "required": ["id", "name", "inputs", "outputs", "formula_id"],
      "properties": {
        "id": { "$ref": "#/definitions/Slug" },
        "name": { "type": "string" },
        "summary": { "type": "string" },
        "formula_id": { "$ref": "#/definitions/Slug" },
        "inputs": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["id", "label", "type"],
            "properties": {
              "id": { "$ref": "#/definitions/ParamId" },
              "label": { "type": "string" },
              "type": { "type": "string", "enum": ["number", "percent", "currency", "integer", "string", "boolean", "array<number>"] },
              "unit": { "type": "string" },
              "default": {},
              "min": { "type": "number" },
              "max": { "type": "number" },
              "required": { "type": "boolean" },
              "description": { "type": "string" }
            }
          }
        },
        "outputs": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["id", "label", "type"],
            "properties": {
              "id": { "$ref": "#/definitions/ParamId" },
              "label": { "type": "string" },
              "type": { "type": "string" },
              "unit": { "type": "string" },
              "description": { "type": "string" }
            }
          }
        },
        "reference_implementation": {
          "type": "object",
          "properties": {
            "language": { "type": "string", "enum": ["javascript", "python", "pseudo"] },
            "code": { "type": "string" }
          }
        },
        "examples": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": { "type": "string" },
              "inputs": { "type": "object" },
              "outputs": { "type": "object" }
            }
          }
        }
      }
    },
    "Regulation": {
      "type": "object",
      "required": ["id", "name", "jurisdiction", "summary"],
      "properties": {
        "id": { "$ref": "#/definitions/Slug" },
        "name": { "type": "string" },
        "long_name": { "type": "string" },
        "jurisdiction": { "type": "string", "enum": ["US", "EU", "UK", "JP", "HK", "SG", "CH", "global"] },
        "regulator": { "type": "string" },
        "year_enacted": { "type": "integer" },
        "summary": { "type": "string" },
        "scope": { "type": "string" },
        "applies_to": { "type": "array", "items": { "type": "string" } },
        "key_provisions": { "type": "array", "items": { "type": "string" } },
        "filings": { "type": "array", "items": { "type": "object", "properties": { "form": { "type": "string" }, "frequency": { "type": "string" }, "purpose": { "type": "string" } } } },
        "thresholds": { "type": "object" },
        "penalties": { "type": "string" },
        "related": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "official_url": { "type": "string", "format": "uri" },
        "sources": { "type": "array", "items": { "$ref": "#/definitions/Source" } }
      }
    },
    "Event": {
      "type": "object",
      "required": ["id", "name", "date", "summary"],
      "properties": {
        "id": { "$ref": "#/definitions/Slug" },
        "name": { "type": "string" },
        "date": { "type": "string", "format": "date" },
        "date_precision": { "type": "string", "enum": ["day", "month", "year"] },
        "summary": { "type": "string" },
        "actors": { "type": "array", "items": { "type": "string" } },
        "mechanism": { "type": "string" },
        "magnitude_usd": { "type": "string" },
        "lessons": { "type": "array", "items": { "type": "string" } },
        "tags": { "type": "array", "items": { "type": "string" } },
        "see_also": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "sources": { "type": "array", "items": { "$ref": "#/definitions/Source" } }
      }
    },
    "Person": {
      "type": "object",
      "required": ["id", "name", "role"],
      "properties": {
        "id": { "$ref": "#/definitions/Slug" },
        "name": { "type": "string" },
        "role": { "type": "string", "enum": ["pm", "founder", "allocator", "operator", "researcher", "regulator", "academic"] },
        "firm": { "type": "string" },
        "firm_url": { "type": "string", "format": "uri" },
        "city": { "type": "string" },
        "country": { "type": "string" },
        "education": { "type": "array", "items": { "type": "string" } },
        "strategies": { "type": "array", "items": { "$ref": "#/definitions/Reference" } },
        "scoring": {
          "type": "object",
          "description": "5-dimension scoring (1-10 each).",
          "properties": {
            "track_record": { "type": "number" },
            "originality": { "type": "number" },
            "operational": { "type": "number" },
            "narrative": { "type": "number" },
            "ecosystem_impact": { "type": "number" }
          }
        },
        "verified": { "type": "boolean" },
        "sources": { "type": "array", "items": { "$ref": "#/definitions/Source" } }
      }
    },
    "Chunk": {
      "type": "object",
      "required": ["id", "text", "source"],
      "properties": {
        "id": { "$ref": "#/definitions/Slug" },
        "text": { "type": "string" },
        "title": { "type": "string" },
        "source": { "type": "string", "format": "uri", "description": "Canonical URL where this chunk lives." },
        "entity": { "$ref": "#/definitions/Reference" },
        "tokens_approx": { "type": "integer" },
        "tags": { "type": "array", "items": { "type": "string" } }
      }
    },
    "Manifest": {
      "type": "object",
      "description": "Top-level API descriptor (this file)."
    }
  }
}
