{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "CAMP Users maintenance",
  "$ref": "#/$defs/root",
  "$defs": {
    "filePath": {
      "type": "string",
      "pattern": "^(\\./|\\.\\./|/)?[A-Za-z0-9._/\\-]+\\.ya?ml$"
    },
    "domainRule": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "domain": {
          "type": "string",
          "pattern": "^[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"
        },
        "mode": {
          "type": "string",
          "enum": [
            "exclusive",
            "present",
            "absent"
          ]
        },
        "defaults": {
          "$ref": "./user.common.schema.json#/$defs/defaults"
        },
        "users": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "./user.common.schema.json#/$defs/userSpec"
          }
        }
      },
      "required": [
        "domain",
        "mode",
        "users"
      ],
      "allOf": [
        {
          "if": {
            "properties": {
              "mode": {
                "const": "absent"
              }
            }
          },
          "then": {
            "allOf": [
              {
                "not": {
                  "required": [
                    "defaults"
                  ]
                }
              },
              {
                "properties": {
                  "users": {
                    "items": {
                      "type": "object",
                      "additionalProperties": false,
                      "properties": {
                        "mailbox": {
                          "type": "string",
                          "pattern": "^[^@\\s]+$"
                        }
                      },
                      "required": [
                        "mailbox"
                      ]
                    }
                  }
                }
              }
            ]
          }
        }
      ]
    },
    "root": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "version": {
          "type": "integer",
          "const": 1
        },
        "disabled": {
          "oneOf": [
            {
              "type": "boolean"
            },
            {
              "type": "object",
              "description": "The pause spelled out, as CAMP writes it from the menu.",
              "additionalProperties": false,
              "properties": {
                "why": {
                  "type": "string",
                  "description": "The reason, for whoever finds it paused."
                },
                "by": {
                  "type": "string",
                  "description": "Who paused it, as git names them."
                },
                "since": {
                  "type": "string",
                  "format": "date",
                  "description": "The day it was paused."
                }
              }
            }
          ]
        },
        "includes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/filePath"
          },
          "uniqueItems": true,
          "minItems": 1
        },
        "domains": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/domainRule"
          }
        }
      },
      "required": [
        "version"
      ]
    }
  }
}
