{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.loyumi.com/schemas/widget-page.v0.1.json",
  "title": "Loyumi Widget Studio preview document",
  "description": "Validation contract for a device-local Loyumi Widget Studio draft. This preview schema does not imply availability of a hosted widget runtime.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "id", "name", "revision", "updatedAt", "theme", "canvas", "blocks"],
  "properties": {
    "$schema": {
      "type": "string",
      "const": "https://docs.loyumi.com/schemas/widget-page.v0.1.json"
    },
    "schemaVersion": { "const": 1 },
    "id": { "type": "string", "minLength": 1 },
    "name": { "type": "string", "minLength": 1 },
    "revision": { "type": "integer", "minimum": 1 },
    "updatedAt": { "type": "string", "format": "date-time" },
    "theme": {
      "type": "object",
      "additionalProperties": false,
      "required": ["accent", "background", "surface", "text", "radius", "font"],
      "properties": {
        "accent": { "$ref": "#/$defs/hexColor" },
        "background": { "$ref": "#/$defs/hexColor" },
        "surface": { "$ref": "#/$defs/hexColor" },
        "text": { "$ref": "#/$defs/hexColor" },
        "radius": { "type": "number", "minimum": 0, "maximum": 48 },
        "font": { "enum": ["system", "serif"] }
      }
    },
    "canvas": {
      "type": "object",
      "additionalProperties": false,
      "required": ["maxWidth", "gap"],
      "properties": {
        "maxWidth": { "type": "number", "minimum": 280, "maximum": 1600 },
        "gap": { "type": "number", "minimum": 0, "maximum": 64 }
      }
    },
    "blocks": {
      "type": "array",
      "items": { "$ref": "#/$defs/widgetBlock" }
    }
  },
  "$defs": {
    "hexColor": {
      "type": "string",
      "pattern": "^#[0-9A-Fa-f]{6}$"
    },
    "widgetBlock": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "type", "props", "visibility"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "type": {
          "enum": ["balance", "tier-progress", "reward-catalog", "earn-preview", "referral", "activity"]
        },
        "props": {
          "type": "object",
          "additionalProperties": {
            "type": ["string", "number", "boolean"]
          }
        },
        "visibility": {
          "type": "object",
          "additionalProperties": false,
          "required": ["mobile", "desktop"],
          "properties": {
            "mobile": { "type": "boolean" },
            "desktop": { "type": "boolean" }
          }
        }
      }
    }
  }
}
