{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "research/viz/program.schema.json",
  "title": "Program po razinama (format iz research/viz/README.md)",
  "description": "AI građanski koncept, PRIJEDLOG. Shema provjerava oblik zapisa; geometrijska i visinska pravila provjerava scripts/viz/program_alat.py provjeri. Nepoznata polja shema dopušta, a alat ih prijavljuje kao upozorenje. Površine se ne upisuju: računa ih alat.",
  "type": "object",
  "required": ["meta", "razine", "prostori", "veze"],
  "properties": {
    "meta": {
      "type": "object",
      "required": ["naziv", "datum", "status", "koordinate"],
      "properties": {
        "naziv": { "type": "string", "minLength": 1 },
        "verzija": { "type": ["string", "number"] },
        "datum": { "type": "string", "minLength": 4 },
        "status": { "type": "string", "minLength": 1 },
        "koordinate": { "type": "string", "minLength": 1 },
        "autor_kandidata": { "type": ["string", "null"] }
      }
    },
    "razine": {
      "type": "array",
      "minItems": 1,
      "items": { "$ref": "#/$defs/razina" }
    },
    "prostori": {
      "type": "array",
      "items": { "$ref": "#/$defs/prostor" }
    },
    "veze": {
      "type": "array",
      "items": { "$ref": "#/$defs/veza" }
    },
    "kote_terena": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["x", "y", "z"],
        "properties": {
          "x": { "type": "number" },
          "y": { "type": "number" },
          "z": { "type": "number" },
          "napomena": { "type": ["string", "null"] }
        }
      }
    },
    "stadion": { "$ref": "#/$defs/stadion" }
  },
  "$defs": {
    "tocka": {
      "type": "array",
      "minItems": 2,
      "maxItems": 2,
      "items": { "type": "number" }
    },
    "prsten": {
      "description": "Zatvoreni niz točaka [x, y] u lokalnom ENU sustavu, u metrima; zadnja točka ne mora ponoviti prvu.",
      "type": "array",
      "minItems": 3,
      "items": { "$ref": "#/$defs/tocka" }
    },
    "linija": {
      "type": "array",
      "minItems": 2,
      "items": { "$ref": "#/$defs/tocka" }
    },
    "status": {
      "type": "string",
      "enum": ["POTVRĐENO", "PRIJEDLOG", "PRETPOSTAVKA-IZRAČUN", "OTVORENO"]
    },
    "razina": {
      "type": "object",
      "required": ["id", "naziv", "kota_poda_mnv", "obris"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "naziv": { "type": "string", "minLength": 1 },
        "kota_poda_mnv": { "type": "number" },
        "svijetla_visina_m": { "type": ["number", "null"], "exclusiveMinimum": 0 },
        "obris": { "$ref": "#/$defs/prsten" },
        "opis": { "type": ["string", "null"] },
        "status": { "$ref": "#/$defs/status" }
      }
    },
    "prostor": {
      "type": "object",
      "required": ["id", "razina", "naziv", "kategorija", "poligon"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "razina": { "type": "string", "minLength": 1 },
        "naziv": { "type": "string", "minLength": 1 },
        "kategorija": {
          "type": "string",
          "enum": [
            "stadion", "igraliste", "tribine", "sport_zatvoreni", "sport_otvoreni", "zdravlje",
            "kultura", "javne_sluzbe", "komercijala", "ugostiteljstvo", "garaza", "promet_tramvaj",
            "promet_bus", "promet_cesta", "topli_put", "trg_predvorje", "tehnika", "logistika",
            "park_zelenilo", "staza", "svjetlarnik", "voda", "dvoriste", "postojece"
          ]
        },
        "poligon": { "$ref": "#/$defs/prsten" },
        "rupe": {
          "description": "Neobvezno: unutarnji prstenovi poligona (dvorište, otvor iznad igrališta).",
          "type": "array",
          "items": { "$ref": "#/$defs/prsten" }
        },
        "kota_poda_mnv": { "type": ["number", "null"] },
        "svijetla_visina_m": { "type": ["number", "null"], "exclusiveMinimum": 0 },
        "sportovi": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "olimpijski_razred": { "enum": ["A", "B", null] },
        "kapacitet": {
          "anyOf": [
            { "type": "null" },
            {
              "type": "object",
              "required": ["vrsta", "broj"],
              "properties": {
                "vrsta": { "type": "string", "minLength": 1 },
                "broj": { "type": "number", "minimum": 0 }
              }
            }
          ]
        },
        "odluke": { "type": "array", "items": { "type": "string", "minLength": 1 } },
        "status": { "$ref": "#/$defs/status" },
        "izvor": { "type": ["string", "null"] },
        "napomena": { "type": ["string", "null"] }
      }
    },
    "veza": {
      "type": "object",
      "required": ["id", "tip", "razine"],
      "anyOf": [
        { "required": ["linija"] },
        { "required": ["tocka"] }
      ],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "tip": {
          "type": "string",
          "enum": [
            "topli_put", "dizalo", "stubiste", "pokretne_stube", "rampa", "svjetlarnik", "ulaz",
            "kolni_ulaz", "evakuacija"
          ]
        },
        "razine": { "type": "array", "minItems": 1, "items": { "type": "string", "minLength": 1 } },
        "linija": { "$ref": "#/$defs/linija" },
        "tocka": { "$ref": "#/$defs/tocka" },
        "sirina_m": { "type": ["number", "null"], "exclusiveMinimum": 0 },
        "nagib_posto": { "type": ["number", "null"], "minimum": 0 },
        "napomena": { "type": ["string", "null"] }
      }
    },
    "stadion": {
      "description": "Gruba geometrija zdjele, krova i pročelja za 3D model; sve PRETPOSTAVKA dok nema projekta.",
      "type": "object",
      "required": ["sredina", "igraliste", "vanjski_obris"],
      "properties": {
        "sredina": { "$ref": "#/$defs/tocka" },
        "os": { "type": "string" },
        "igraliste": { "$ref": "#/$defs/prsten" },
        "vanjski_obris": { "$ref": "#/$defs/prsten" },
        "tribine": {
          "type": "array",
          "items": {
            "type": "object",
            "required": ["naziv", "unutarnji_obris", "vanjski_obris", "kota_dna_mnv", "kota_vrha_mnv"],
            "properties": {
              "naziv": { "type": "string", "minLength": 1 },
              "unutarnji_obris": { "$ref": "#/$defs/prsten" },
              "vanjski_obris": { "$ref": "#/$defs/prsten" },
              "kota_dna_mnv": { "type": "number" },
              "kota_vrha_mnv": { "type": "number" },
              "mjesta": { "type": ["number", "null"], "minimum": 0 }
            }
          }
        },
        "krov": {
          "type": "object",
          "properties": {
            "unutarnji_rub": { "$ref": "#/$defs/prsten" },
            "vanjski_rub": { "$ref": "#/$defs/prsten" },
            "kota_ruba_mnv": { "type": "number" },
            "kota_vrha_mnv": { "type": "number" }
          }
        },
        "procelje": {
          "type": "object",
          "properties": {
            "kota_dna_mnv": { "type": "number" },
            "kota_vrha_mnv": { "type": "number" },
            "razmak_lamela_m": { "type": "number", "exclusiveMinimum": 0 }
          }
        }
      }
    }
  }
}
