{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rangka-os.github.io/rangka-os/schema/0.5/overlay.json",
  "title": "Rangka model overlay",
  "description": "Company layer (layer 4): fields, rules and view tweaks an organisation adds to an app model, in <site>/custom/<model>.rk. The kernel merges them onto the app model at load; app upgrades never touch them.",
  "type": "object",
  "required": [
    "model"
  ],
  "additionalProperties": false,
  "properties": {
    "$schema": {
      "type": "string"
    },
    "model": {
      "$ref": "model.json#/$defs/name",
      "description": "The app model this overlay extends; must equal the file name"
    },
    "label": {
      "$ref": "model.json#/$defs/label",
      "description": "The company's word for the model (page title, the create button, widget titles); replaces the app model's label (contract 0049 §5)"
    },
    "labels": {
      "type": "object",
      "description": "The company's words for fields of the app model, by field name; each replaces that field's label (contract 0049 §5)",
      "propertyNames": {
        "pattern": "^[a-z][a-z0-9_]{0,62}$"
      },
      "additionalProperties": {
        "$ref": "model.json#/$defs/label"
      }
    },
    "fields": {
      "type": "array",
      "items": {
        "allOf": [
          {
            "$ref": "model.json#/$defs/field"
          },
          {
            "properties": {
              "name": {
                "type": "string",
                "pattern": "^x_[a-z0-9_]{1,60}$",
                "description": "Company fields start with x_"
              }
            }
          }
        ]
      }
    },
    "rules": {
      "type": "array",
      "items": {
        "$ref": "model.json#/$defs/rule"
      }
    },
    "approvals": {
      "type": "array",
      "items": {
        "$ref": "model.json#/$defs/approval"
      }
    },
    "views": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "form": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "add": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/add"
              }
            },
            "layout": {
              "type": "array",
              "items": {
                "$ref": "model.json#/$defs/section"
              },
              "minItems": 1,
              "description": "Replaces the app model's form layout; fields it leaves out are not shown (views.form.add still applies after it)"
            }
          }
        },
        "list": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "add": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/add"
              }
            },
            "columns": {
              "type": "array",
              "items": {
                "$ref": "model.json#/$defs/listcol"
              },
              "minItems": 1,
              "description": "Replaces the list columns (views.list.add still applies after it)"
            }
          }
        },
        "kanban": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "columns": {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1,
              "description": "Order of the kanban group_by option values; values left out are hidden"
            }
          }
        }
      }
    },
    "options": {
      "type": "object",
      "description": "Options appended to a select field of the model, by field name",
      "additionalProperties": {
        "type": "array",
        "items": {
          "$ref": "model.json#/$defs/option"
        }
      }
    }
  },
  "$defs": {
    "add": {
      "type": "object",
      "required": [
        "field"
      ],
      "additionalProperties": false,
      "properties": {
        "field": {
          "$ref": "model.json#/$defs/name"
        },
        "after": {
          "$ref": "model.json#/$defs/name",
          "description": "Place after this field or column; at the end when omitted"
        }
      }
    }
  }
}
