{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://cardnetwork.org/spec/v1.1/card-schema.json",
  "title": "CNA Card Schema",
  "description": "Schema for Card Network Architecture cards - atomic content units (~250 tokens)",
  "type": "object",
  "required": ["id", "type", "header", "body"],
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "description": "Unique identifier for the card"
    },
    "type": {
      "type": "string",
      "enum": ["content", "action", "decision", "media", "data", "embed", "composite"],
      "description": "Card type determining behavior and rendering"
    },
    "status": {
      "type": "string",
      "enum": ["draft", "review", "validating", "published", "archived"],
      "default": "draft",
      "description": "Card lifecycle status"
    },
    "quality_score": {
      "type": "number",
      "minimum": 0,
      "maximum": 100,
      "description": "Quality score (0-100) based on completeness, accuracy, and connectivity"
    },
    "author": {
      "type": "string",
      "description": "Primary author or creator of the card"
    },
    "version": {
      "type": "string",
      "default": "1.0",
      "description": "Card content version"
    },
    "last_validated": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp of last validation pass"
    },
    "namespace": {
      "type": "string",
      "default": "@personalos",
      "description": "Namespace for card scoping and multi-tenant isolation"
    },
    "header": {
      "type": "object",
      "description": "Card header with title and optional icon",
      "required": ["title"],
      "properties": {
        "title": {
          "type": "string",
          "maxLength": 100,
          "description": "Card title (max 100 characters)"
        },
        "icon": {
          "type": "string",
          "description": "Icon identifier (e.g., 'info', 'warning', 'code')"
        },
        "subtitle": {
          "type": "string",
          "maxLength": 200,
          "description": "Optional subtitle"
        }
      }
    },
    "body": {
      "type": "object",
      "description": "Card body content",
      "properties": {
        "text": {
          "type": "string",
          "description": "Plain text content"
        },
        "markdown": {
          "type": "string",
          "description": "Markdown formatted content"
        },
        "code": {
          "type": "string",
          "description": "Code snippet"
        },
        "codeLanguage": {
          "type": "string",
          "description": "Programming language for syntax highlighting"
        },
        "media": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/mediaRef"
          },
          "description": "Array of media references"
        },
        "data": {
          "type": "object",
          "description": "Structured data (for data cards)"
        },
        "actions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/action"
          },
          "description": "Action buttons (for action cards)"
        },
        "choices": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/choice"
          },
          "description": "Decision options (for decision cards)"
        }
      }
    },
    "metadata": {
      "type": "object",
      "description": "Card metadata",
      "properties": {
        "tags": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Categorization tags"
        },
        "created": {
          "type": "string",
          "format": "date-time",
          "description": "Creation timestamp"
        },
        "updated": {
          "type": "string",
          "format": "date-time",
          "description": "Last update timestamp"
        },
        "author": {
          "type": "string",
          "description": "Card author"
        },
        "version": {
          "type": "string",
          "description": "Card version"
        },
        "tokens": {
          "type": "integer",
          "minimum": 0,
          "description": "Estimated token count for LLM context"
        },
        "priority": {
          "type": "integer",
          "minimum": 0,
          "maximum": 10,
          "description": "Priority for context selection (0-10)"
        }
      }
    },
    "connectors": {
      "type": "object",
      "description": "Visual connection points for edges",
      "properties": {
        "top": { "type": "boolean", "default": false },
        "bottom": { "type": "boolean", "default": false },
        "left": { "type": "boolean", "default": false },
        "right": { "type": "boolean", "default": false }
      }
    },
    "style": {
      "type": "object",
      "description": "Optional visual styling",
      "properties": {
        "backgroundColor": { "type": "string" },
        "borderColor": { "type": "string" },
        "textColor": { "type": "string" }
      }
    }
  },
  "$defs": {
    "mediaRef": {
      "type": "object",
      "required": ["type", "url"],
      "properties": {
        "type": { "type": "string", "enum": ["image", "video", "audio", "file"] },
        "url": { "type": "string", "format": "uri" },
        "alt": { "type": "string" },
        "caption": { "type": "string" }
      }
    },
    "action": {
      "type": "object",
      "required": ["id", "label"],
      "properties": {
        "id": { "type": "string" },
        "label": { "type": "string" },
        "type": { "type": "string", "enum": ["primary", "secondary", "danger"], "default": "primary" },
        "action": { "type": "string", "description": "Action identifier or URL" }
      }
    },
    "choice": {
      "type": "object",
      "required": ["id", "label", "target"],
      "properties": {
        "id": { "type": "string" },
        "label": { "type": "string" },
        "description": { "type": "string" },
        "target": { "type": "string", "description": "Target card ID" }
      }
    }
  }
}