{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://developers.youareaccountable.com/schemas/coaching_session.updated.json",
  "title": "CoachingSessionUpdated",
  "description": "A session is changed, a series is changed from a date onward, or a session's attendance is recorded. A series change has data.scope set to future.",
  "type": "object",
  "required": [
    "event_type",
    "data"
  ],
  "properties": {
    "event_type": {
      "const": "coaching_session.updated"
    },
    "data": {
      "oneOf": [
        {
          "title": "CoachingSessionUpdatedOneSession",
          "description": "One session.",
          "type": "object",
          "required": [
            "medical_record_number",
            "session_id",
            "recurrence_group_id",
            "scheduled_date",
            "status"
          ],
          "properties": {
            "medical_record_number": {
              "type": "string",
              "format": "uuid",
              "description": "The member's medical record number. Always a UUID. Use it to match the event to your own record."
            },
            "plan_name": {
              "type": [
                "string",
                "null"
              ],
              "description": "The member's Accountable plan. Can be null or left out."
            },
            "session_id": {
              "type": "string",
              "description": "The session's ID."
            },
            "recurrence_group_id": {
              "type": [
                "string",
                "null"
              ],
              "description": "The series ID. null when the session is not part of a series."
            },
            "scheduled_date": {
              "type": "string",
              "format": "date-time",
              "description": "The scheduled start time after the change."
            },
            "end_time": {
              "type": [
                "string",
                "null"
              ],
              "format": "date-time",
              "description": "The scheduled end time after the change."
            },
            "duration_minutes": {
              "type": [
                "number",
                "null"
              ],
              "description": "The scheduled length."
            },
            "status": {
              "enum": [
                "scheduled",
                "completed",
                "canceled",
                "no-show"
              ]
            }
          }
        },
        {
          "title": "CoachingSessionUpdatedSeries",
          "description": "Every session in a series from a date onward.",
          "type": "object",
          "required": [
            "medical_record_number",
            "recurrence_group_id",
            "scope",
            "effective_from",
            "recurrence_rule"
          ],
          "properties": {
            "medical_record_number": {
              "type": "string",
              "format": "uuid",
              "description": "The member's medical record number. Always a UUID. Use it to match the event to your own record."
            },
            "plan_name": {
              "type": [
                "string",
                "null"
              ],
              "description": "The member's Accountable plan. Can be null or left out."
            },
            "recurrence_group_id": {
              "type": "string",
              "description": "The series ID."
            },
            "scope": {
              "const": "future"
            },
            "effective_from": {
              "type": "string",
              "format": "date-time",
              "description": "The first session the change applies to."
            },
            "duration_minutes": {
              "type": [
                "number",
                "null"
              ],
              "description": "The scheduled length."
            },
            "recurrence_rule": {
              "type": [
                "object",
                "null"
              ],
              "description": "The new time and day.",
              "properties": {
                "time_utc": {
                  "type": [
                    "string",
                    "null"
                  ],
                  "pattern": "^[0-9]{2}:[0-9]{2}$",
                  "description": "Start time in UTC, as HH:mm."
                },
                "day_of_week": {
                  "type": [
                    "integer",
                    "null"
                  ],
                  "minimum": 0,
                  "maximum": 6,
                  "description": "0 is Sunday, 6 is Saturday."
                }
              }
            }
          }
        }
      ]
    }
  },
  "examples": [
    {
      "event_type": "coaching_session.updated",
      "data": {
        "medical_record_number": "3f2b8c1e-7a4d-4e9b-9c55-0d6a1f2e8b47",
        "plan_name": "Standard Plan",
        "session_id": "665f1c2ab7e4d90012a3f4c5",
        "recurrence_group_id": null,
        "scheduled_date": "2026-01-06T16:00:00.000Z",
        "end_time": "2026-01-06T16:30:00.000Z",
        "duration_minutes": 30,
        "status": "scheduled"
      }
    },
    {
      "event_type": "coaching_session.updated",
      "data": {
        "medical_record_number": "3f2b8c1e-7a4d-4e9b-9c55-0d6a1f2e8b47",
        "plan_name": "Standard Plan",
        "recurrence_group_id": "0b9d6c1e-5d2a-4a57-8f43-2f6a9d3c7e10",
        "scope": "future",
        "effective_from": "2026-02-03T16:00:00.000Z",
        "duration_minutes": 30,
        "recurrence_rule": {
          "time_utc": "16:00",
          "day_of_week": 2
        }
      }
    }
  ]
}
