{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "urn:exploder-kit:catalogue-layer:1",
 "title": "The product catalogue in the Exploder",
 "description": "04-assets/catalogue.json, written by studio/catalogue.py apply from a product-catalogue@1 snapshot in the intake. The identity each installed item gives its scene component, and one plan's options with each placement drawn where its site_ref puts it, or listed as unplaced with the reason. Read by the page (opts.catalogue, js/placements.js and the Asset view).",
 "type": "object",
 "required": ["kind", "contract", "catalogue_version", "snapshot", "snapshot_sha256", "pulled_at", "site", "installed_base_version", "plan", "default_option", "states", "identity", "unmatched", "options"],
 "additionalProperties": false,
 "$defs": {
  "not_known": {
   "type": "object",
   "required": ["state", "why"],
   "properties": {"state": {"const": "not_known"}, "why": {"type": "string", "minLength": 1}, "would_answer": {"type": "string"}}
  },
  "placement": {
   "type": "object",
   "required": ["id", "for", "for_name", "what", "quantity", "state", "why", "coverage", "model", "candidates", "price", "gaps"],
   "additionalProperties": false,
   "properties": {
    "id": {"type": "string"},
    "for": {"type": "string"},
    "for_name": {"type": "string"},
    "what": {"type": "string", "description": "A model id, or a sensor type id when no model is chosen"},
    "quantity": {"type": "integer", "minimum": 1},
    "state": {"enum": ["met", "partly_met", "not_met", "feed", "none"], "description": "feed: it reads an existing feed (why.uses_existing_feed). Otherwise the best state of the coverage lines that name it; none: no coverage line names it"},
    "why": {"type": "object", "required": ["requirements"]},
    "coverage": {"type": "array", "items": {"type": "object", "required": ["requirement", "state"]}},
    "position": {"type": ["object", "null"]},
    "site_ref": {"type": ["object", "null"]},
    "at": {"type": "object", "required": ["kind", "id", "at", "name", "source"], "properties": {"at": {"type": "array", "minItems": 3, "maxItems": 3, "items": {"type": "number"}}}},
    "unplaced": {"type": "string", "minLength": 1},
    "model": {"type": ["object", "null"], "required": ["id", "name", "maker", "kind", "status", "sources", "documents", "price"]},
    "candidates": {"type": "array", "items": {"type": "object", "required": ["id", "name"]}},
    "price": {"oneOf": [{"type": "null"}, {"type": "object", "required": ["unit", "line_total", "line_quantity", "bom_item"]}]},
    "gaps": {"type": "array", "items": {"type": "object", "required": ["kind", "subject", "why"]}}
   },
   "oneOf": [{"required": ["at"]}, {"required": ["unplaced"]}]
  }
 },
 "properties": {
  "kind": {"const": "exploder-kit/catalogue-layer@1"},
  "contract": {"const": "product-catalogue@1"},
  "catalogue_version": {"type": "string"},
  "snapshot": {"type": "string"},
  "snapshot_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
  "pulled_at": {"type": "string"},
  "site": {"type": "string"},
  "installed_base_version": {"type": "integer"},
  "plan": {"type": "object", "required": ["id", "made_at", "inputs"]},
  "default_option": {"type": "string"},
  "states": {"type": "object"},
  "identity": {"type": "object", "additionalProperties": {"type": "object", "required": ["maker", "model", "in_service", "catalogue"]}},
  "unmatched": {"type": "array", "items": {"type": "object", "required": ["item", "why"]}},
  "options": {
   "type": "array",
   "minItems": 1,
   "items": {
    "type": "object",
    "required": ["name", "totals", "counts", "placements", "unplaced", "coverage", "gaps"],
    "properties": {
     "name": {"type": "string"},
     "placements": {"type": "array", "items": {"$ref": "#/$defs/placement"}},
     "unplaced": {"type": "array", "items": {"$ref": "#/$defs/placement"}}
    }
   }
  }
 }
}
