{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.healthexport.dev/schemas/webhook/v1/strength-log.json",
  "title": "MetricBridge webhook: strength log",
  "description": "The complete strength log the user keeps in the app: sessions with their sets, each exercise's records, and saved routines. Opt-in. Replace what you stored: a session missing from the list was deleted. Load is in kilograms. Estimates are never a load to attempt.",
  "allOf": [{ "$ref": "common.json#/$defs/typedDocument" }],
  "type": "object",
  "properties": {
    "type": { "const": "strength.log" },
    "data": {
      "type": "object",
      "required": ["metrics", "strengthLog"],
      "properties": {
        "strengthLog": {
          "type": "object",
          "required": ["mode", "unit", "formula", "sessions", "records"],
          "properties": {
            "mode": { "const": "replace" },
            "unit": { "const": "kg" },
            "formula": { "type": "string", "description": "Names the version of the derived maths, e.g. strength-v1." },
            "sessions": {
              "type": "array",
              "description": "Oldest first.",
              "items": {
                "type": "object",
                "required": ["id", "start", "day", "volumeKg", "workingSets", "exercises"],
                "properties": {
                  "id": { "type": "string" },
                  "start": { "$ref": "common.json#/$defs/localDateTime" },
                  "day": { "$ref": "common.json#/$defs/isoDay", "description": "The local day the session was logged for. Group by this." },
                  "minutes": { "type": "number" },
                  "effort": { "type": "number", "description": "Session RPE, 1 to 10." },
                  "workoutId": { "type": "string" },
                  "routineId": { "type": "string" },
                  "notes": { "type": "string" },
                  "volumeKg": { "type": "number", "description": "Sum of reps x kg over working sets." },
                  "workingSets": { "type": "integer" },
                  "exercises": {
                    "type": "array",
                    "items": {
                      "type": "object",
                      "required": ["name", "volumeKg", "sets"],
                      "properties": {
                        "name": { "type": "string", "description": "The person's own text or a preset's English key." },
                        "volumeKg": { "type": "number" },
                        "bestEstimateKg": { "type": "number", "description": "Epley estimate over working sets of 1 to 10 reps. Absent when no set qualifies." },
                        "sets": {
                          "type": "array",
                          "items": {
                            "type": "object",
                            "required": ["reps", "kind"],
                            "properties": {
                              "reps": { "type": "integer" },
                              "kg": { "type": "number", "description": "Absent for a bodyweight set with nothing added, never 0." },
                              "kind": { "enum": ["warmup", "working"] },
                              "rpe": { "type": "number" }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            },
            "records": {
              "type": "array",
              "description": "One per exercise with at least one working set. Accept unknown extra fields.",
              "items": {
                "type": "object",
                "required": ["exercise"],
                "properties": {
                  "exercise": { "type": "string" },
                  "bestEstimateKg": { "type": "number" },
                  "bestEstimateDay": { "$ref": "common.json#/$defs/isoDay" },
                  "heaviestKg": { "type": "number" },
                  "sessions": { "type": "integer" },
                  "lastDay": { "$ref": "common.json#/$defs/isoDay" }
                }
              }
            },
            "routines": {
              "type": "array",
              "description": "Saved templates, the person's own plans.",
              "items": {
                "type": "object",
                "required": ["id", "name"],
                "properties": {
                  "id": { "type": "string" },
                  "name": { "type": "string" },
                  "createdAt": { "type": "string", "format": "date-time" },
                  "lastUsedDay": { "$ref": "common.json#/$defs/isoDay" },
                  "exercises": { "type": "array" }
                }
              }
            }
          }
        }
      }
    }
  }
}
