{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "DisplayX Config Schema",
  "description": "JSON Schema for DisplayX digital signage configuration",
  "type": "object",
  "required": ["version", "package_version", "assets", "schedule", "fallback"],
  "properties": {
    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+$",
      "description": "Config format version (e.g., '1.0')"
    },
    "package_version": {
      "type": "string",
      "format": "date-time",
      "description": "ISO8601 timestamp of config publication"
    },
    "settings": {
      "type": "object",
      "properties": {
        "cache_size_gb": {
          "type": "number",
          "minimum": 0.1,
          "maximum": 100,
          "default": 5
        },
        "poll_interval_sec": {
          "type": "integer",
          "minimum": 5,
          "maximum": 3600,
          "default": 300
        },
        "health_report_url": {
          "type": "string",
          "format": "uri"
        },
        "analytics_webhook": {
          "type": "string",
          "format": "uri"
        },
        "respect_reduced_motion": {
          "type": "boolean",
          "default": true
        }
      }
    },
    "assets": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["id", "type", "url", "cached"],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 64
          },
          "type": {
            "type": "string",
            "enum": ["image", "video", "live_stream"]
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "cached": {
            "type": "boolean",
            "description": "If true, player MUST pre-download; if false, stream-only"
          }
        }
      }
    },
    "schedule": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["time_range", "playlist", "durations_sec"],
        "properties": {
          "time_range": {
            "type": "array",
            "items": {
              "type": "string",
              "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$"
            },
            "minItems": 2,
            "maxItems": 2,
            "description": "Start and end time in HH:MM format (24-hour)"
          },
          "playlist": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "description": "Asset IDs to play during this time range"
          },
          "durations_sec": {
            "type": "array",
            "items": {
              "type": ["number", "null"],
              "minimum": 1
            },
            "minItems": 1,
            "description": "Duration in seconds for each asset; null = play until block ends"
          },
          "transition": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": ["crossfade", "fade-to-black", "hard-cut"]
              },
              "duration_ms": {
                "type": "integer",
                "minimum": 0,
                "maximum": 2000
              }
            },
            "required": ["type", "duration_ms"]
          },
          "conditions": {
            "type": "object",
            "properties": {
              "date_range": {
                "type": "array",
                "items": {
                  "type": "string",
                  "format": "date"
                },
                "minItems": 2,
                "maxItems": 2
              },
              "device_tags": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "fallback": {
      "type": "object",
      "required": ["asset_id", "message"],
      "properties": {
        "asset_id": {
          "type": "string",
          "description": "Asset ID to display when offline or on error"
        },
        "message": {
          "type": "string",
          "maxLength": 128,
          "description": "Message to display in offline badge"
        }
      }
    }
  }
}
