{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://christmas-microgames.dev/schema/config.json",
  "title": "Christmas Micro-Games — config.json",
  "description": "Configuration for one game. Every visible text accepts either a plain string or a translations object such as { \"es\": \"Hola\", \"en\": \"Hello\" }.",
  "type": "object",
  "required": ["brand", "game"],
  "definitions": {
    "localized": {
      "description": "Plain text, or one text per language code: { \"es\": \"…\", \"en\": \"…\" }.",
      "oneOf": [
        { "type": "string" },
        {
          "type": "object",
          "minProperties": 1,
          "propertyNames": { "pattern": "^[a-z]{2,3}(-[A-Za-z]{2,4})?$" },
          "additionalProperties": { "type": "string" }
        }
      ]
    },
    "color": { "type": "string", "pattern": "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$" },
    "url": { "type": "string", "pattern": "^(https?://|/|\\./|\\.\\./|[A-Za-z0-9_-])" },
    "prize": {
      "type": "object",
      "required": ["id", "label", "probability", "type"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "label": { "$ref": "#/definitions/localized" },
        "probability": {
          "type": "number",
          "minimum": 0,
          "description": "Relative weight. Weights do not need to add up to 100."
        },
        "type": {
          "enum": ["coupon", "discount", "physical", "digital", "entry", "none"],
          "description": "\"none\" = losing segment (\"So close!\")."
        },
        "value": {
          "type": "string",
          "description": "Coupon code shown to the winner (hidden for physical/entry/none)."
        },
        "image": { "type": "string" },
        "terms": { "$ref": "#/definitions/localized" },
        "color": { "$ref": "#/definitions/color", "description": "Wheel segment colour (spin-wheel)." }
      }
    },
    "question": {
      "type": "object",
      "required": ["id", "question", "options", "correctIndex"],
      "additionalProperties": false,
      "properties": {
        "id": { "type": "string" },
        "question": { "$ref": "#/definitions/localized" },
        "options": { "type": "array", "minItems": 2, "maxItems": 6, "items": { "$ref": "#/definitions/localized" } },
        "correctIndex": { "type": "integer", "minimum": 0 },
        "explanation": { "$ref": "#/definitions/localized" },
        "image": { "type": "string" },
        "points": { "type": "integer", "minimum": 0, "default": 100 },
        "timeLimit": { "type": "integer", "minimum": 5, "maximum": 120, "default": 20 }
      }
    }
  },
  "properties": {
    "$schema": { "type": "string" },
    "$comment": { "type": "string" },
    "brand": {
      "type": "object",
      "required": ["primary", "secondary", "company", "ctaText", "ctaUrl"],
      "additionalProperties": false,
      "properties": {
        "logo": { "type": "string", "description": "Logo URL (SVG/PNG/WebP). Empty = company name as text." },
        "primary": { "$ref": "#/definitions/color", "description": "Buttons and highlights." },
        "secondary": { "$ref": "#/definitions/color", "description": "Background tint." },
        "accent": { "$ref": "#/definitions/color", "description": "Gold details, combos, prize card." },
        "font": { "type": "string", "default": "'Inter', system-ui, sans-serif" },
        "company": { "type": "string" },
        "ctaText": { "$ref": "#/definitions/localized" },
        "ctaUrl": {
          "$ref": "#/definitions/url",
          "description": "Only http(s) or relative URLs are accepted (javascript: is blocked)."
        },
        "favicon": { "type": "string" },
        "loadingMessage": { "$ref": "#/definitions/localized" }
      }
    },
    "game": {
      "type": "object",
      "required": ["id"],
      "additionalProperties": false,
      "properties": {
        "id": { "enum": ["snowball-fight", "gift-catch", "santa-runner", "memory-match", "quiz-trivia", "spin-wheel"] },
        "difficulty": { "enum": ["easy", "medium", "hard"], "default": "medium" },
        "rounds": { "type": "integer", "minimum": 1, "maximum": 20, "default": 1 },
        "timeLimit": {
          "type": "integer",
          "minimum": 10,
          "maximum": 600,
          "default": 60,
          "description": "Seconds (timed games)."
        },
        "lives": { "type": "integer", "minimum": 1, "maximum": 9, "default": 3 },
        "theme": { "type": "string", "default": "christmas" },
        "title": { "$ref": "#/definitions/localized", "description": "Overrides the translated default title." },
        "instructions": { "$ref": "#/definitions/localized" },
        "winScore": {
          "type": "number",
          "minimum": 0,
          "default": 0,
          "description": "Score needed to win the prize / see the CTA. 0 = always win."
        },
        "customAssets": {
          "type": "object",
          "description": "Override any texture: { \"bg\": \"assets/my-background.webp\", \"gift\": \"assets/my-product.png\" }.",
          "additionalProperties": { "type": "string" }
        },
        "prizes": { "type": "array", "items": { "$ref": "#/definitions/prize" } },
        "questions": { "type": "array", "maxItems": 50, "items": { "$ref": "#/definitions/question" } },
        "cardPairs": { "type": "integer", "minimum": 3, "maximum": 12, "default": 8 }
      }
    },
    "gdpr": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": { "type": "boolean", "default": true },
        "consentMode": { "enum": ["opt-in", "opt-out"], "default": "opt-in", "description": "EU: keep opt-in." },
        "categories": { "type": "array", "items": { "enum": ["necessary", "analytics", "marketing"] } },
        "dataRetentionDays": { "type": "integer", "minimum": 1, "default": 30 },
        "dsrEndpoint": {
          "type": "string",
          "description": "Optional POST endpoint notified on data deletion requests."
        },
        "privacyPolicyUrl": { "type": "string" },
        "cookieName": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,64}$", "default": "xmas_game_consent" }
      }
    },
    "analytics": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": { "type": "boolean", "default": false },
        "provider": { "enum": ["ga4", "gtm", "matomo", "custom", "none"], "default": "none" },
        "measurementId": { "type": "string", "description": "GA4: G-XXXX · GTM: GTM-XXXX" },
        "matomoUrl": { "type": "string" },
        "matomoSiteId": { "type": "integer" },
        "customEndpoint": { "type": "string" },
        "anonymizeIp": { "type": "boolean", "default": true },
        "events": { "type": "array", "items": { "type": "string" }, "description": "Allow-list. Empty = all events." }
      }
    },
    "localization": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "defaultLanguage": { "type": "string", "default": "es" },
        "supportedLanguages": {
          "type": "array",
          "items": { "enum": ["es", "en", "fr", "de", "it", "pt", "ca", "eu", "gl", "ar"] },
          "description": "Languages offered in the selector. ?lang=xx in the URL forces one."
        },
        "rtlLanguages": { "type": "array", "items": { "type": "string" } },
        "autoDetect": { "type": "boolean", "default": true },
        "fallbackLanguage": { "type": "string", "default": "en" }
      }
    },
    "lead": {
      "type": "object",
      "description": "GDPR-friendly lead capture (explicit consent checkbox, no pre-ticked boxes).",
      "additionalProperties": false,
      "properties": {
        "enabled": { "type": "boolean", "default": false },
        "endpoint": {
          "type": "string",
          "description": "POST JSON { name, email, phone?, consent, gameId, lang, score, prizeId, ts }. Works with Zapier/Make/n8n webhooks."
        },
        "mode": {
          "enum": ["before-prize", "after"],
          "default": "after",
          "description": "before-prize: the coupon code is revealed only after the form."
        },
        "fields": {
          "type": "array",
          "items": { "enum": ["name", "email", "phone"] },
          "minItems": 1,
          "uniqueItems": true
        },
        "consentText": { "$ref": "#/definitions/localized" }
      }
    },
    "leaderboard": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": { "type": "boolean", "default": false },
        "provider": { "enum": ["local", "supabase", "custom"], "default": "local" },
        "supabaseConfig": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "url": { "type": "string" },
            "anonKey": { "type": "string" },
            "table": { "type": "string", "default": "leaderboard" }
          }
        },
        "customEndpoint": { "type": "string" },
        "maxEntries": { "type": "integer", "minimum": 3, "maximum": 100, "default": 10 },
        "showAvatar": { "type": "boolean", "default": false },
        "requireName": { "type": "boolean", "default": true }
      }
    },
    "social": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": { "type": "boolean", "default": true },
        "shareText": {
          "$ref": "#/definitions/localized",
          "description": "Placeholders: {score} {prize} {company} {url}"
        },
        "shareUrl": { "type": "string" },
        "shareImage": { "type": "string" },
        "platforms": {
          "type": "array",
          "items": { "enum": ["whatsapp", "x", "twitter", "facebook", "linkedin", "email", "copy"] }
        }
      }
    },
    "audio": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "enabled": { "type": "boolean", "default": true },
        "volume": { "type": "number", "minimum": 0, "maximum": 1, "default": 0.6 }
      }
    },
    "performance": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "lazyLoadAssets": { "type": "boolean" },
        "preloadCritical": { "type": "boolean" },
        "serviceWorker": { "type": "boolean" },
        "compression": { "enum": ["gzip", "brotli", "both"] }
      }
    }
  }
}
