{
  "$schema": "https://json-schema.org/draft-07/schema#",
  "$id": "https://nextrep.app/export.schema.json",
  "title": "NextRepExport",
  "description": "An export of data from the NextRep app",
  "type": "object",
  "required": [
    "meta",
    "workouts",
    "templates",
    "exercises"
  ],
  "properties": {
    "meta": {
      "type": "object",
      "required": [
        "nrVersion",
        "nrBuildNumber",
        "nrSchemaVersion",
        "exportDate"
      ],
      "properties": {
        "nrVersion": {
          "type": "string",
          "readOnly": true
        },
        "nrBuildNumber": {
          "type": "string",
          "readOnly": true
        },
        "nrSchemaVersion": {
          "type": "integer",
          "readOnly": true
        },
        "exportDate": {
          "type": "string",
          "readOnly": true,
          "format": "date-time"
        }
      }
    },
    "workouts": {
      "type": "array",
      "items": {
        "title": "Workout",
        "type": "object",
        "required": [
          "id",
          "name",
          "startTime",
          "exercises"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "startTime": {
            "type": "string",
            "format": "date-time"
          },
          "endTime": {
            "type": "string",
            "format": "date-time"
          },
          "rpe": {
            "type": "integer",
            "minimum": 0,
            "maximum": 10
          },
          "notes": {
            "type": "string"
          },
          "exercises": {
            "type": "array",
            "items": {
              "title": "WorkoutExercise",
              "type": "object",
              "required": [
                "id",
                "exerciseId",
                "sets"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "exerciseId": {
                  "type": "string",
                  "format": "uuid"
                },
                "notes": {
                  "type": "string"
                },
                "supersetGroupId": {
                  "type": "string",
                  "format": "uuid"
                },
                "sets": {
                  "type": "array",
                  "items": {
                    "title": "WorkoutSet",
                    "type": "object",
                    "$ref": "#/$defs/genericSet",
                    "required": [
                      "id",
                      "completed"
                    ],
                    "properties": {
                      "completed": {
                        "type": "boolean",
                        "default": false
                      },
                      "timestamp": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "templates": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "name",
          "createdAt",
          "exercises"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "exercises": {
            "type": "array",
            "items": {
              "title": "TemplateExercise",
              "type": "object",
              "required": [
                "id",
                "exerciseId",
                "sets"
              ],
              "properties": {
                "id": {
                  "type": "string",
                  "format": "uuid"
                },
                "exerciseId": {
                  "type": "string",
                  "format": "uuid"
                },
                "notes": {
                  "type": "string"
                },
                "supersetGroupId": {
                  "type": "string",
                  "format": "uuid"
                },
                "sets": {
                  "title": "TemplateSet",
                  "type": "array",
                  "items": {
                    "type": "object",
                    "$ref": "#/$defs/genericSet"
                  }
                }
              }
            }
          }
        }
      }
    },
    "exercises": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "id",
          "name"
        ],
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "measurementType": {
            "enum": [
              "weightReps",
              "time",
              "distance"
            ],
            "default": "weightReps"
          }
        }
      }
    }
  },
  "$defs": {
    "genericSet": {
      "type": "object",
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "type": "string",
          "format": "uuid"
        },
        "weight": {
          "type": "number"
        },
        "reps": {
          "type": "integer",
          "minimum": 0
        },
        "duration": {
          "type": "number",
          "minimum": 0
        },
        "distance": {
          "type": "number",
          "minimum": 0
        },
        "restTime": {
          "type": "number",
          "minimum": 0
        }
      }
    }
  }
}
