{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "allOf": [
    {
      "type": "object",
      "properties": {
        "lift_assist_version": {
          "type": "string",
          "const": "1"
        },
        "workout_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._-]{1,100}$"
        },
        "set_id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._-]{1,100}$"
        },
        "workout_name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 1000
        },
        "started_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))$"
            },
            {
              "type": "string",
              "allOf": [
                {
                  "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
                },
                {
                  "pattern": "(?:Z|[+-](?:0[0-9]|1[0-4]):[0-5][0-9])$"
                }
              ]
            }
          ]
        },
        "exercise": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "finished_at": {
          "type": "string",
          "allOf": [
            {
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
            },
            {
              "pattern": "(?:Z|[+-](?:0[0-9]|1[0-4]):[0-5][0-9])$"
            }
          ]
        },
        "performed_at": {
          "type": "string",
          "allOf": [
            {
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
            },
            {
              "pattern": "(?:Z|[+-](?:0[0-9]|1[0-4]):[0-5][0-9])$"
            }
          ]
        },
        "set_kind": {
          "type": "string",
          "enum": [
            "warmup",
            "working",
            "other"
          ]
        },
        "reps": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,4}|100000)$"
        },
        "rep_basis": {
          "type": "string",
          "enum": [
            "total",
            "per_side",
            "unknown"
          ]
        },
        "duration_seconds": {
          "type": "string",
          "allOf": [
            {
              "pattern": "^(?=(?:[^0-9]*[0-9]){1,12}$)(?:0|[1-9][0-9]*)(?:\\.[0-9]{1,6})?$"
            },
            {
              "pattern": "^(?!0(?:\\.0+)?$)"
            }
          ]
        },
        "distance_m": {
          "type": "string",
          "allOf": [
            {
              "pattern": "^(?=(?:[^0-9]*[0-9]){1,12}$)(?:0|[1-9][0-9]*)(?:\\.[0-9]{1,6})?$"
            },
            {
              "pattern": "^(?!0(?:\\.0+)?$)"
            }
          ]
        },
        "load_kind": {
          "type": "string",
          "enum": [
            "total",
            "per_implement",
            "bodyweight",
            "added",
            "assistance"
          ]
        },
        "weight": {
          "type": "string",
          "pattern": "^(?=(?:[^0-9]*[0-9]){1,12}$)(?:0|[1-9][0-9]*)(?:\\.[0-9]{1,6})?$"
        },
        "weight_unit": {
          "type": "string",
          "enum": [
            "kg",
            "lb"
          ]
        },
        "implement_count": {
          "type": "string",
          "pattern": "^(?:[1-9][0-9]?|100)$"
        },
        "body_mass": {
          "type": "string",
          "allOf": [
            {
              "pattern": "^(?=(?:[^0-9]*[0-9]){1,12}$)(?:0|[1-9][0-9]*)(?:\\.[0-9]{1,6})?$"
            },
            {
              "pattern": "^(?!0(?:\\.0+)?$)"
            }
          ]
        },
        "rpe": {
          "type": "string",
          "pattern": "^(?:[1-9](?:\\.[05])?|10(?:\\.0)?)$"
        },
        "rir": {
          "type": "string",
          "pattern": "^(?:[0-9](?:\\.[05])?|10(?:\\.0)?)$"
        },
        "set_note": {
          "type": "string",
          "maxLength": 10000
        },
        "workout_note": {
          "type": "string",
          "maxLength": 10000
        }
      },
      "required": [
        "lift_assist_version",
        "workout_id",
        "set_id",
        "workout_name",
        "started_at",
        "exercise"
      ],
      "additionalProperties": false
    },
    {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "load_kind": {
              "not": {}
            },
            "weight": {
              "not": {}
            },
            "weight_unit": {
              "not": {}
            },
            "implement_count": {
              "not": {}
            },
            "body_mass": {
              "not": {}
            }
          }
        },
        {
          "type": "object",
          "properties": {
            "load_kind": {
              "type": "string",
              "const": "total"
            },
            "weight": {
              "type": "string"
            },
            "weight_unit": {
              "type": "string"
            },
            "body_mass": {
              "not": {}
            },
            "implement_count": {
              "not": {}
            }
          },
          "required": [
            "load_kind",
            "weight",
            "weight_unit"
          ]
        },
        {
          "type": "object",
          "properties": {
            "load_kind": {
              "type": "string",
              "const": "per_implement"
            },
            "weight": {
              "type": "string"
            },
            "weight_unit": {
              "type": "string"
            },
            "body_mass": {
              "not": {}
            },
            "implement_count": {
              "type": "string"
            }
          },
          "required": [
            "load_kind",
            "weight",
            "weight_unit",
            "implement_count"
          ]
        },
        {
          "type": "object",
          "properties": {
            "load_kind": {
              "type": "string",
              "const": "bodyweight"
            },
            "weight": {
              "not": {}
            },
            "implement_count": {
              "not": {}
            },
            "body_mass": {
              "not": {}
            },
            "weight_unit": {
              "not": {}
            }
          },
          "required": [
            "load_kind"
          ]
        },
        {
          "type": "object",
          "properties": {
            "load_kind": {
              "type": "string",
              "const": "bodyweight"
            },
            "weight": {
              "not": {}
            },
            "implement_count": {
              "not": {}
            },
            "body_mass": {
              "type": "string"
            },
            "weight_unit": {
              "type": "string"
            }
          },
          "required": [
            "load_kind",
            "body_mass",
            "weight_unit"
          ]
        },
        {
          "type": "object",
          "properties": {
            "load_kind": {
              "type": "string",
              "const": "added"
            },
            "weight": {
              "type": "string"
            },
            "weight_unit": {
              "type": "string"
            },
            "implement_count": {
              "not": {}
            }
          },
          "required": [
            "load_kind",
            "weight",
            "weight_unit"
          ]
        },
        {
          "type": "object",
          "properties": {
            "load_kind": {
              "type": "string",
              "const": "assistance"
            },
            "weight": {
              "type": "string",
              "allOf": [
                {
                  "pattern": "^(?=(?:[^0-9]*[0-9]){1,12}$)(?:0|[1-9][0-9]*)(?:\\.[0-9]{1,6})?$"
                },
                {
                  "pattern": "^(?!0(?:\\.0+)?$)"
                }
              ]
            },
            "weight_unit": {
              "type": "string"
            },
            "implement_count": {
              "not": {}
            }
          },
          "required": [
            "load_kind",
            "weight",
            "weight_unit"
          ]
        }
      ]
    },
    {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "reps": {
              "type": "string"
            }
          },
          "required": [
            "reps"
          ]
        },
        {
          "type": "object",
          "properties": {
            "duration_seconds": {
              "type": "string"
            },
            "rep_basis": {
              "not": {}
            }
          },
          "required": [
            "duration_seconds"
          ]
        },
        {
          "type": "object",
          "properties": {
            "distance_m": {
              "type": "string"
            },
            "rep_basis": {
              "not": {}
            }
          },
          "required": [
            "distance_m"
          ]
        }
      ]
    },
    {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "rpe": {
              "not": {}
            }
          }
        },
        {
          "type": "object",
          "properties": {
            "rir": {
              "not": {}
            }
          }
        }
      ]
    }
  ],
  "title": "Re-Phase workout history CSV v1",
  "description": "Validate one record after trimming cells and omitting empty values. Column headers are the property names. Workout fields must agree for each workout_id. The pair workout_id and set_id must be unique in a file."
}
