{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://interchange.stellarview.net/schemas/load_template.schema.json",
  "title": "A load template: the sheet a site fills in, as columns with types, rules and an example. The template is the schema.",
  "type": "object",
  "required": ["id", "title", "makes", "instructions", "columns"],
  "additionalProperties": false,
  "properties": {
    "id": { "type": "string", "pattern": "^[a-z][a-z_]*$" },
    "title": { "type": "string" },
    "makes": { "type": "string", "description": "What each row becomes: an Interchange contract, or a setup record." },
    "instructions": { "type": "array", "minItems": 1, "items": { "type": "string" } },
    "columns": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["name", "type", "required", "meaning", "example"],
        "additionalProperties": false,
        "properties": {
          "name": { "type": "string", "pattern": "^[a-z][a-z0-9_]*$" },
          "type": { "enum": ["string", "integer", "number", "date", "enum", "list"] },
          "required": { "type": "boolean" },
          "meaning": { "type": "string" },
          "values": { "type": "array", "minItems": 1, "items": { "type": "string" } },
          "ref": {
            "enum": ["catalogue:asset_class", "catalogue:event_type", "catalogue:sensor_type", "catalogue:unit"],
            "description": "Every value must be an id in MissionSight's catalogue. On a list column, every item."
          },
          "pattern": { "type": "string" },
          "minimum": { "type": "number" },
          "example": { "type": "string", "description": "The example row's value. Empty for an optional column left blank." }
        },
        "if": { "properties": { "type": { "const": "enum" } } },
        "then": { "required": ["values"] }
      }
    }
  }
}
