{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://betterpds.com.au/schemas/pds.schema.json",
  "title": "Better PDS — structured PDS representation",
  "description": "Canonical machine-readable shape of an insurance Product Disclosure Statement (PDS). The renderer (shared/tools/render.mjs), the chatbot, and the feedback-loop analyser all consume this shape. Schema version: 1.",
  "type": "object",
  "required": ["meta", "summary_for_customer", "sections"],
  "properties": {
    "schema_version": { "const": 1 },
    "meta": {
      "type": "object",
      "required": ["product_name", "region", "effective_date", "source_url", "insurer", "agent_brand"],
      "properties": {
        "slug":              { "type": "string", "pattern": "^[a-z0-9-]+$", "description": "Unique slug for this insurer/product, e.g. freely-au." },
        "product_name":      { "type": "string" },
        "product_type":      { "type": "string", "enum": ["travel", "home", "health", "life", "car", "pet", "super", "other"] },
        "region":            { "type": "string" },
        "document_title":    { "type": "string" },
        "effective_date":    { "type": "string", "format": "date" },
        "source_filename":   { "type": "string" },
        "source_url":        { "type": "string", "format": "uri" },
        "source_sha256":     { "type": "string" },
        "source_page_count": { "type": "integer", "minimum": 1 },
        "insurer": {
          "type": "object",
          "required": ["legal_name"],
          "properties": {
            "legal_name": { "type": "string" },
            "abn":        { "type": "string" },
            "afsl":       { "type": "string" }
          }
        },
        "distributor": {
          "type": "object",
          "properties": {
            "legal_name": { "type": "string" },
            "afsl":       { "type": "string" }
          }
        },
        "agent_brand":      { "type": "string", "description": "Customer-facing brand name." },
        "version":          { "type": "string", "description": "Output release version (semver-ish)." },
        "structured_by":    { "type": "string" },
        "structured_at":    { "type": "string", "format": "date" }
      }
    },
    "brand": {
      "type": "object",
      "description": "Per-insurer brand overrides applied as CSS variables in the rendered page.",
      "properties": {
        "primary":    { "type": "string", "description": "hex color" },
        "primary_deep": { "type": "string" },
        "ink":        { "type": "string" },
        "accent":     { "type": "string" },
        "wordmark":   { "type": "string" },
        "wordmark_style": { "type": "string", "enum": ["italic-script", "uppercase-bold", "modern-sans"] },
        "logo_url":   { "type": "string", "format": "uri" }
      }
    },
    "reading_time_minutes": { "type": "integer", "minimum": 1 },
    "summary_for_customer": { "type": "string" },
    "key_things_to_know":   { "type": "array", "items": { "type": "string" } },
    "sections": {
      "type": "array",
      "items": { "$ref": "#/definitions/Section" }
    },
    "glossary": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["term", "definition"],
        "properties": {
          "term":       { "type": "string" },
          "definition": { "type": "string" },
          "see_also":   { "type": "array", "items": { "type": "string" } }
        }
      }
    },
    "support": {
      "type": "object",
      "properties": {
        "claims_email": { "type": "string", "format": "email" },
        "claims_phone": { "type": "string" },
        "post":         { "type": "string" },
        "online":       { "type": "string", "format": "uri" },
        "claims_url":   { "type": "string", "format": "uri" }
      }
    }
  },
  "definitions": {
    "Section": {
      "type": "object",
      "required": ["id", "title"],
      "properties": {
        "id":            { "type": "string", "pattern": "^[a-z0-9-]+$" },
        "title":         { "type": "string" },
        "source_pages":  { "type": "array", "items": { "type": "integer" } },
        "plain_summary": { "type": "string", "description": "One-liner that prefixes the section with 'In one line: …'" },
        "callouts":      {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["type", "text"],
            "properties": {
              "type": { "type": "string", "enum": ["tip", "warning", "danger"] },
              "text": { "type": "string" }
            }
          }
        },
        "warnings":          { "type": "array", "items": { "type": "string" } },
        "what_to_do":        { "type": "array", "items": { "type": "string" } },
        "steps":             { "type": "array", "items": { "type": "string" } },
        "structure":         { "type": "object" },
        "limits_table": {
          "type": "object",
          "required": ["name", "rows"],
          "description": "Cover-limits table. Two shapes: (1) single-tier — each row has benefit + limit + optional note; (2) multi-tier — set top-level 'columns' to the tier names (e.g. ['Top','Standard','Budget','Basic']) and give each row a 'values' array of the same length.",
          "properties": {
            "name":    { "type": "string" },
            "columns": { "type": "array", "items": { "type": "string" }, "description": "Optional. When present, rows use 'values' instead of 'limit' to populate one cell per column." },
            "rows": {
              "type": "array",
              "items": {
                "type": "object",
                "required": ["benefit"],
                "properties": {
                  "benefit": { "type": "string" },
                  "limit":   { "type": "string", "description": "Single-tier shape." },
                  "values":  { "type": "array", "items": { "type": "string" }, "description": "Multi-tier shape. Length must match the table's 'columns'." },
                  "note":    { "type": "string" },
                  "indent":  { "type": "boolean", "description": "If true, render the benefit name indented (sub-limit row)." }
                }
              }
            },
            "footnotes": { "type": "array", "items": { "type": "string" } }
          }
        },
        "boosts": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["name", "type", "plain_summary"],
            "properties": {
              "name":          { "type": "string" },
              "type":          { "type": "string", "enum": ["Trip Boost", "Daily Boost", "Add-on", "Optional"] },
              "plain_summary": { "type": "string" },
              "must_add_before_leaving": { "type": "boolean" }
            }
          }
        },
        "auto_covered_examples":     { "type": "array", "items": { "$ref": "#/definitions/CriterionRow" } },
        "needs_assessment_examples": { "type": "array", "items": { "type": "string" } },
        "important_definitions":     { "type": "array", "items": { "type": "string" } },
        "key_points":                { "type": "array", "items": { "type": "string" } },
        "benefits": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["name"],
            "properties": {
              "number":       { "type": "integer" },
              "name":         { "type": "string" },
              "covered":      { "type": "array", "items": { "type": "string" } },
              "not_covered":  { "type": "array", "items": { "type": "string" } },
              "source_pages": { "type": "array", "items": { "type": "integer" } }
            }
          }
        },
        "exclusions":   { "type": "array", "items": { "type": "string" } },
        "subsections":  {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["title", "summary"],
            "properties": {
              "title":   { "type": "string" },
              "summary": { "type": "string" }
            }
          }
        },
        "what_to_have_ready": { "type": "array", "items": { "type": "string" } },
        "contact": {
          "type": "object",
          "properties": {
            "claims_email": { "type": "string", "format": "email" },
            "claims_phone": { "type": "string" }
          }
        }
      }
    },
    "CriterionRow": {
      "type": "object",
      "required": ["condition", "criteria"],
      "properties": {
        "condition": { "type": "string" },
        "criteria":  { "type": "string" }
      }
    }
  }
}
