{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://timesheet.io/schemas/report-render-request-v1.schema.json",
  "title": "Timesheet Report Render Request v1",
  "type": "object",
  "additionalProperties": false,
  "required": ["templateId", "templateVersion", "platform", "placement", "payload"],
  "properties": {
    "templateId": { "enum": ["monthly-wrapped", "yearly-wrapped"] },
    "templateVersion": { "const": 1 },
    "platform": { "enum": ["instagram", "facebook", "tiktok", "youtube", "threads", "linkedin", "generic"] },
    "placement": { "enum": ["post", "reel", "story", "short"] },
    "payload": { "$ref": "#/$defs/payload" }
  },
  "$defs": {
    "payload": {
      "type": "object",
      "additionalProperties": false,
      "required": ["schemaVersion", "reportType", "period", "locale", "timeZone", "stats", "distribution", "activity", "achievements", "visibility"],
      "properties": {
        "schemaVersion": { "const": 1 },
        "reportType": { "enum": ["month", "year"] },
        "period": { "$ref": "#/$defs/period" },
        "locale": { "type": "string", "maxLength": 35 },
        "timeZone": { "type": "string", "maxLength": 64 },
        "stats": { "$ref": "#/$defs/stats" },
        "distribution": { "type": "array", "maxItems": 12, "items": { "$ref": "#/$defs/distributionItem" } },
        "activity": { "$ref": "#/$defs/activity" },
        "achievements": { "type": "array", "maxItems": 8, "items": { "$ref": "#/$defs/achievement" } },
        "comparison": { "anyOf": [{ "$ref": "#/$defs/comparison" }, { "type": "null" }] },
        "visibility": { "$ref": "#/$defs/visibility" }
      }
    },
    "period": {
      "type": "object",
      "additionalProperties": false,
      "required": ["start", "end", "label"],
      "properties": {
        "start": { "type": "string", "format": "date" },
        "end": { "type": "string", "format": "date" },
        "label": { "type": "string", "maxLength": 80 }
      }
    },
    "stats": {
      "type": "object",
      "additionalProperties": false,
      "required": ["trackedSeconds", "activeDays", "projectCount", "tagCount", "averageSecondsPerActiveDay", "longestStreak", "mostActiveWeekday"],
      "properties": {
        "trackedSeconds": { "type": "integer", "minimum": 0 },
        "activeDays": { "type": "integer", "minimum": 0, "maximum": 366 },
        "projectCount": { "type": "integer", "minimum": 0 },
        "tagCount": { "type": "integer", "minimum": 0 },
        "averageSecondsPerActiveDay": { "type": "integer", "minimum": 0 },
        "longestStreak": { "type": "integer", "minimum": 0, "maximum": 366 },
        "mostActiveWeekday": { "anyOf": [{ "type": "integer", "minimum": 1, "maximum": 7 }, { "type": "null" }] }
      }
    },
    "distributionItem": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "percentage", "trackedSeconds"],
      "properties": {
        "id": { "type": "string", "maxLength": 64 },
        "label": { "type": ["string", "null"], "maxLength": 60 },
        "percentage": { "type": "number", "minimum": 0, "maximum": 100 },
        "trackedSeconds": { "type": "integer", "minimum": 0 }
      }
    },
    "activity": {
      "type": "object",
      "additionalProperties": false,
      "required": ["days"],
      "properties": {
        "days": {
          "type": "array",
          "maxItems": 366,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["date", "intensity"],
            "properties": {
              "date": { "type": "string", "format": "date" },
              "intensity": { "type": "integer", "minimum": 0, "maximum": 4 }
            }
          }
        }
      }
    },
    "achievement": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "type", "value"],
      "properties": {
        "id": { "type": "string", "maxLength": 64 },
        "type": { "type": "string", "maxLength": 40 },
        "value": { "type": "integer", "minimum": 0 }
      }
    },
    "comparison": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "trackedTimeChangePercent": { "type": ["number", "null"] },
        "activeDaysChange": { "type": ["integer", "null"] },
        "projectCountChange": { "type": ["integer", "null"] }
      }
    },
    "visibility": {
      "type": "object",
      "additionalProperties": false,
      "required": ["showTrackedTime", "showProjectNames", "showActivity", "showAchievements", "showComparison"],
      "properties": {
        "showTrackedTime": { "type": "boolean" },
        "showProjectNames": { "type": "boolean" },
        "showActivity": { "type": "boolean" },
        "showAchievements": { "type": "boolean" },
        "showComparison": { "type": "boolean" }
      }
    }
  }
}
