{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Results file",
  "description": "Layout of the per-market/year JSON files and of draws.json.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "dataset",
    "license",
    "attribution",
    "documentation",
    "session_note",
    "count",
    "results"
  ],
  "properties": {
    "dataset": {
      "type": "string"
    },
    "license": {
      "const": "CC-BY-4.0"
    },
    "attribution": {
      "type": "string"
    },
    "documentation": {
      "type": "string"
    },
    "session_note": {
      "type": "string"
    },
    "market": {
      "type": "string",
      "enum": [
        "SG",
        "HK",
        "SDY",
        "MC",
        "CAM"
      ]
    },
    "year": {
      "type": "integer"
    },
    "count": {
      "type": "integer",
      "minimum": 0
    },
    "results": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/draw"
      }
    }
  },
  "$defs": {
    "draw": {
      "title": "Draw",
      "description": "One draw result. Unique key: market + draw_date + session + draw_type.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "market",
        "draw_type",
        "draw_date",
        "session",
        "session_timezone",
        "result"
      ],
      "properties": {
        "market": {
          "type": "string",
          "enum": [
            "SG",
            "HK",
            "SDY",
            "MC",
            "CAM"
          ],
          "description": "Market code."
        },
        "draw_type": {
          "const": "4D",
          "description": "Draw format. Always 4D in this release."
        },
        "draw_date": {
          "type": "string",
          "format": "date",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$",
          "description": "Calendar date (YYYY-MM-DD) under which the compiled archives list the draw."
        },
        "session": {
          "type": "string",
          "pattern": "^([01]\\d|2[0-3]):[0-5]\\d$",
          "description": "Draw time label HH:MM as published by the compiled archives, in WIB (Asia/Jakarta). A label, not a verified timestamp."
        },
        "session_timezone": {
          "const": "Asia/Jakarta",
          "description": "Time zone of the session label. Not the local time zone of the market."
        },
        "result": {
          "type": "string",
          "pattern": "^\\d{4}$",
          "description": "Four-digit result as a string. Leading zeros are significant (\"0678\")."
        }
      }
    }
  }
}
