{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Tjuvkik panel.json",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "type"
  ],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "description": {
      "type": "string",
      "description": "What the panel shows, in one sentence."
    },
    "author": {
      "type": "string"
    },
    "version": {
      "type": "string",
      "examples": [
        "1.0.0"
      ]
    },
    "requires": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[^/]+$"
      },
      "description": "Commands that must be on PATH, like \"gh\". The tile says which are missing instead of failing.",
      "examples": [
        [
          "gh",
          "jq"
        ]
      ]
    },
    "type": {
      "enum": [
        "script",
        "cli",
        "chart",
        "meters",
        "grid",
        "timeline",
        "stats",
        "markdown",
        "keyvalue",
        "table",
        "feed",
        "checklist"
      ],
      "description": "script prints JSON that the tile draws by its top-level key, rows by default; cli shows the output as is. A content type, like stats, is a script panel drawn as that type."
    },
    "mode": {
      "enum": [
        "interval",
        "stream"
      ],
      "default": "interval",
      "description": "interval runs the command every `every`. stream keeps it running: each line a script prints is a new JSON document, and a cli panel shows the latest lines. Restarted if it exits."
    },
    "title": {
      "type": "string",
      "description": "Defaults to the folder name."
    },
    "command": {
      "type": "string",
      "description": "Run with /bin/sh -c in this panel's folder, with your login shell's PATH."
    },
    "every": {
      "type": "string",
      "pattern": "^\\s*[0-9.]+\\s*(ms|s|m|h)\\s*$",
      "examples": [
        "30s",
        "5m",
        "1h"
      ],
      "default": "60s",
      "description": "How often to refresh an interval panel. At least 5s."
    },
    "timeout": {
      "type": "string",
      "pattern": "^\\s*[0-9.]+\\s*(ms|s|m|h)\\s*$",
      "examples": [
        "30s",
        "5m",
        "1h"
      ],
      "default": "10s",
      "description": "How long an interval panel's command may run."
    },
    "background": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "string",
          "pattern": "^\\s*[0-9.]+\\s*(ms|s|m|h)\\s*$"
        }
      ],
      "default": true,
      "examples": [
        "5m",
        false
      ],
      "description": "How often an interval panel runs while the glance is closed. true: every `every`. false: only while you glance. At least 5s."
    },
    "notify": {
      "anyOf": [
        {
          "type": "boolean"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "sound": {
              "type": "boolean"
            },
            "minInterval": {
              "type": "string",
              "pattern": "^\\s*[0-9.]+\\s*(ms|s|m|h)\\s*$",
              "examples": [
                "1m"
              ],
              "description": "At most one notification this often. The rest are grouped."
            },
            "on": {
              "type": "array",
              "items": {
                "enum": [
                  "failed",
                  "warning",
                  "error"
                ]
              },
              "description": "failed: while the panel shows an error. warning, error: rows with that tone."
            }
          }
        }
      ],
      "default": true,
      "description": "false: this panel never notifies."
    },
    "size": {
      "enum": [
        "s",
        "m",
        "l",
        "xl"
      ],
      "description": "Default size; config.json can override it. s 1×1, m 2×1, l 2×2, xl 2×3",
      "default": "s"
    },
    "history": {
      "type": "integer",
      "minimum": 2,
      "maximum": 1000,
      "description": "For a chart whose script prints only the current value: how many values Tjuvkik keeps as its series."
    },
    "file": {
      "type": "string",
      "description": "For a markdown panel: a file to show instead of a command's output, reloaded when it changes. ~, an absolute path, or a path in the panel's folder.",
      "examples": [
        "~/notes/today.md"
      ]
    },
    "options": {
      "type": "object",
      "description": "Settings the panel takes from config.jsonc. The command gets each as TJUVKIK_OPTION_<NAME> and all of them as JSON in TJUVKIK_OPTIONS.",
      "propertyNames": {
        "pattern": "^[A-Za-z][A-Za-z0-9_-]*$"
      },
      "additionalProperties": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "type"
        ],
        "properties": {
          "type": {
            "enum": [
              "string",
              "number",
              "boolean"
            ]
          },
          "title": {
            "type": "string",
            "description": "A label for forms. Default: the option's name."
          },
          "description": {
            "type": "string"
          },
          "default": {
            "type": [
              "string",
              "number",
              "boolean"
            ]
          },
          "required": {
            "type": "boolean",
            "default": false,
            "description": "Every tile of this panel must set it."
          },
          "enum": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "minItems": 1,
            "description": "The allowed values of a string option."
          }
        }
      }
    }
  },
  "if": {
    "required": [
      "file"
    ]
  },
  "then": {
    "properties": {
      "type": {
        "const": "markdown"
      }
    }
  },
  "else": {
    "required": [
      "command"
    ]
  }
}
