{
  "$id": "https://thendoo.com/schemas/thendoo-template-v1.json",
  "title": "Thendoo template file (thendoo-template/v1)",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "format": {
      "type": "string",
      "const": "thendoo-template/v1"
    },
    "id": {
      "type": "string",
      "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120
    },
    "locale": {
      "default": "en",
      "type": "string",
      "pattern": "^[a-z]{2}(-[A-Z]{2})?$"
    },
    "templates": {
      "default": [],
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "type": {
            "type": "string",
            "enum": [
              "task",
              "project",
              "checklist",
              "note",
              "routine"
            ]
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "body": {
            "type": "object",
            "properties": {
              "items": {
                "default": [],
                "maxItems": 200,
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "title": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 500
                    },
                    "offset_days": {
                      "default": null,
                      "anyOf": [
                        {
                          "type": "integer",
                          "minimum": -3650,
                          "maximum": 3650
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "checklist": {
                      "default": [],
                      "maxItems": 100,
                      "type": "array",
                      "items": {
                        "type": "string",
                        "minLength": 1,
                        "maxLength": 500
                      }
                    },
                    "notes": {
                      "default": null,
                      "anyOf": [
                        {
                          "type": "string",
                          "maxLength": 20000
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "title"
                  ],
                  "additionalProperties": false
                }
              },
              "body_md": {
                "default": null,
                "anyOf": [
                  {
                    "type": "string",
                    "maxLength": 100000
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "additionalProperties": false
          }
        },
        "required": [
          "type",
          "name",
          "body"
        ],
        "additionalProperties": false
      }
    },
    "habits": {
      "default": [],
      "maxItems": 50,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 200
          },
          "action_text": {
            "default": null,
            "anyOf": [
              {
                "type": "string",
                "maxLength": 2000
              },
              {
                "type": "null"
              }
            ]
          },
          "cue": {
            "default": null,
            "anyOf": [
              {
                "type": "string",
                "maxLength": 200
              },
              {
                "type": "null"
              }
            ]
          },
          "trigger": {
            "default": {
              "type": "none"
            },
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "none"
                  }
                },
                "required": [
                  "type"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "time"
                  },
                  "at_min": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 1439
                  }
                },
                "required": [
                  "type",
                  "at_min"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "after_habit"
                  },
                  "habit": {
                    "type": "string",
                    "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
                  }
                },
                "required": [
                  "type",
                  "habit"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "event_end"
                  },
                  "title_contains": {
                    "default": null,
                    "anyOf": [
                      {
                        "type": "string",
                        "maxLength": 200
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "type"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "const": "place"
                  },
                  "event": {
                    "default": "arrive",
                    "type": "string",
                    "enum": [
                      "arrive",
                      "leave"
                    ]
                  },
                  "label": {
                    "type": "string",
                    "maxLength": 200
                  }
                },
                "required": [
                  "type",
                  "label"
                ],
                "additionalProperties": false
              }
            ]
          },
          "schedule": {
            "default": {
              "kind": "daily"
            },
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "daily"
                  }
                },
                "required": [
                  "kind"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "weekdays"
                  },
                  "days": {
                    "minItems": 1,
                    "maxItems": 7,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "enum": [
                        "MO",
                        "TU",
                        "WE",
                        "TH",
                        "FR",
                        "SA",
                        "SU"
                      ]
                    }
                  }
                },
                "required": [
                  "kind",
                  "days"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "x_per_week"
                  },
                  "times": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 7
                  }
                },
                "required": [
                  "kind",
                  "times"
                ],
                "additionalProperties": false
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "flexible"
                  }
                },
                "required": [
                  "kind"
                ],
                "additionalProperties": false
              }
            ]
          },
          "streak_rule": {
            "default": {
              "misses_per_week": 1
            },
            "type": "object",
            "properties": {
              "misses_per_week": {
                "default": 1,
                "type": "integer",
                "minimum": 0,
                "maximum": 3
              }
            },
            "additionalProperties": false
          },
          "color": {
            "default": null,
            "anyOf": [
              {
                "type": "string",
                "pattern": "^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$"
              },
              {
                "type": "null"
              }
            ]
          },
          "icon": {
            "default": null,
            "anyOf": [
              {
                "type": "string",
                "maxLength": 40
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "key",
          "name"
        ],
        "additionalProperties": false
      }
    },
    "categories": {
      "default": [],
      "maxItems": 200,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
          },
          "name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120
          },
          "kind": {
            "default": "expense",
            "type": "string",
            "enum": [
              "expense",
              "income",
              "transfer"
            ]
          },
          "parent": {
            "default": null,
            "anyOf": [
              {
                "type": "string",
                "pattern": "^[a-z0-9]+(?:-[a-z0-9]+)*$"
              },
              {
                "type": "null"
              }
            ]
          },
          "color": {
            "default": null,
            "anyOf": [
              {
                "type": "string",
                "pattern": "^#[0-9a-fA-F]{6}([0-9a-fA-F]{2})?$"
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": [
          "key",
          "name"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "format",
    "id",
    "name"
  ],
  "additionalProperties": false
}