{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "title": "Joystream KPI schema",
  "type": "object",
  "required": ["overviewSection", "sections"],
  "properties": {
    "overviewSection": {
      "type": "object",
      "required": [
        "title", 
        "kpisNumber", 
        "councilElectedInRound", 
        "councilMembers", 
        "termLength", 
        "termSummariesForumThread",
        "deadlineToSubmitSummary"
      ],
      "properties": {
        "title": {"type": "string", "maxLength": 16},
        "kpisNumber": {"type": "string", "maxLength": 10},
        "councilElectedInRound": {"type": "number", "min": 0, "max": 1024},
        "councilMembers": {"type": "number", "min": 1, "max": 1024},
        "termLength": {
          "type": "object",
          "required": [
            "termLength", 
            "startBlock", 
            "endBlock", 
            "startDate", 
            "endDate"
          ],
          "properties": {
            "termLength": {"type": "string", "maxLength": 32},
            "startBlock": {"type": "string", "maxLength": 16},
            "endBlock": {"type": "string", "maxLength": 16},
            "startDate": {"type": "string", "format": "date"},
            "endDate": {"type": "string", "format": "date"}
          },
        "termSummariesForumThread": {"type": "string", "maxLength": 1024},
        "deadlineToSubmitSummary": {
          "type": "object",
          "required": ["block", "deadlineDate"],   
          "properties": {
            "block": {"type": "string", "maxLength": 16},
            "deadlineDate": {"type": "string", "format": "date"}
          }
        }
        }
      }
    },
    "sections": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["sectionTitle", "sectionDescription", "kpis"],
        "properties": {
          "sectionTitle": {"type": "string", "maxLength": 1024},
          "sectionDescription": {"type": "string"},
          "kpis": {
            "type": "array",
            "minItems": 1,  
            "items": {
              "type": "object",
              "required": [
                "kpiTitle", 
                "reward", 
                "active", 
                "purpose", 
                "scopeOfWork", 
                "rewardDistribution", 
                "note", 
                "grading"
              ],
              "properties": {
                "kpiTitle": {"type": "string"},
                "reward": {
                  "type": "object",
                  "required": ["rewardLine", "rewardDescription"],
                  "properties": {
                    "rewardLine": {"type": "string"},
                    "rewardDescription": {"type": "string"}
                  }
                },
                "rewardStructure": {
                  "const": "Individual"
                },
                "gradingProcess": {
                  "type": "string", 
                  "enum": [
                      "Manual", 
                      "Automatic"
                    ]
                },
                "active": {
                  "type": "object",
                  "required": ["active"],
                  "properties": {
                    "active": {"type": "string", "maxLength": 16},
                    "block": {"type": "number"},
                    "startBlock": {"type": "string", "maxLength": 16},
                    "endBlock": {"type": "string", "maxLength": 16},
                    "activeDate": {"type": "string", "format": "date"}
                  }
                },
                "purpose": {"type": "string"},
                "scopeOfWork": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": ["task"],
                    "properties": {
                      "task": {"type": "string"}
                    }
                  }
                },
                "rewardDistribution": {"type": "string"},
                "note": {"type": "string"},
                "grading": {"type": "string"},
                "reporting": {"type": "string"},
                "weighting": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "required": ["weight"],
                    "properties": {
                      "weight": {"type": "string"}
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
