{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "TODO File Schema",
  "type": "object",
  "properties": {
    "sprints": {
      "type": "array",
      "items": { "$ref": "#/definitions/Sprint" }
    },
    "issues": {
      "type": "array",
      "items": { "$ref": "#/definitions/Issue" }
    },
    "modules": {
      "type": "array",
      "items": { "$ref": "#/definitions/Module" }
    },
    "bugzilla": {
      "$ref": "#/definitions/BugzillaTracker"
    }
  },
  "required": ["sprints", "issues"],
  "additionalProperties": false,

  "definitions": {
    "Sprint": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "start": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        },
        "end": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        }
      },
      "required": ["name", "start", "end"],
      "additionalProperties": false
    },

    "Issue": {
      "type": "object",
      "properties": {
        "id": {
          "type": "integer",
          "minimum": 1
        },
        "type": {
          "type": "string",
          "enum": ["feature", "bugfix", "hotfix"]
        },
        "title": { "type": "string" },
        "status": {
          "type": "string",
          "enum": ["open", "in-progress", "done", "hold", "cancelled"]
        },
        "priority": {
          "type": "string",
          "enum": ["low", "medium", "high"]
        },
        "created": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        },
        "module": {
          "type": "string"
        },
        "relationships": {
          "$ref": "#/definitions/IssueRelationships"
        },
        "dueStart": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        },
        "dueEnd": {
          "type": "string",
          "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
        },
        "description": { "type": "string" },
        "body": { "type": "string" }
      },
      "required": [
        "id",
        "type",
        "title",
        "status",
        "priority",
        "created",
        "relationships",
        "description",
        "body"
      ],
      "additionalProperties": false
    },

    "IssueRelationships": {
      "type": "object",
      "patternProperties": {
        "^(dependsOn|relatesTo|blocks)$": {
          "type": "array",
          "items": { "type": "integer", "minimum": 1 }
        }
      },
      "additionalProperties": false
    },

    "Module": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "path": { "type": "string" }
      },
      "required": ["name"],
      "additionalProperties": false
    },

    "BugzillaTrackerMapping": {
      "type": "object",
      "properties": {
        "module": { "type": "string" },
        "product": { "type": "string" },
        "component": { "type": "string" }
      },
      "required": ["module", "product", "component"],
      "additionalProperties": false
    },

    "BugzillaTracker": {
      "type": "object",
      "properties": {
        "url": { "type": "string" },
        "mappings": {
          "type": "array",
          "items": { "$ref": "#/definitions/BugzillaTrackerMapping" },
          "minItems": 1
        }
      },
      "required": ["url", "mappings"],
      "additionalProperties": false
    }
  }
}
