openapi: 3.0.3
info:
  title: Caregiver API
  version: 0.1.0
  description: CareToSher API contract — source of truth.
servers:
  - url: https://api.dev.example.com
    description: dev
  - url: https://api.example.com
    description: prod
security:
  - bearerAuth: []
tags:
  - name: Account
    description: >-
      The signed-in caregiver — who they are, their email, closing the account,
      feedback.
  - name: Care teams
    description: Care teams the caregiver belongs to, their members and roles.
  - name: Invitations
    description: Inviting someone to a care team and joining one.
  - name: Care receivers
    description: The people a care team looks after, and what the team keeps about them.
  - name: Trackers
    description: >-
      What a care team tracks for a care receiver, and the templates to start
      from.
  - name: Schedules
    description: When a tracker expects entries.
  - name: Entries
    description: Logged, skipped and scheduled entries on a tracker.
  - name: Home
    description: >-
      What Home reads — what needs attention, what is coming up, the timeline,
      journal notes.
  - name: Coverage
    description: Who is on duty for a care receiver, by assignment and coverage schedule.
  - name: Service
    description: Health and feature flags.
paths:
  /health:
    get:
      tags:
        - Service
      operationId: getHealth
      summary: Health check
      description: Returns service health and build metadata.
      security: []
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Health'
  /flags:
    get:
      tags:
        - Service
      operationId: getFlags
      summary: Return evaluated feature flags
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Flags'
  /v1/me:
    get:
      tags:
        - Account
      operationId: getMyAccount
      summary: The signed-in caregiver and the care teams they belong to
      description: >
        The sign-in resolution. An empty `teams` sends the caregiver to Join a
        care team; anything else sends them to Home. Archived teams are not
        listed. The caller's record is created on first call from the verified
        ID token.
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MyAccount'
        '401':
          $ref: '#/components/responses/Unauthorized'
    patch:
      tags:
        - Account
      operationId: changeMyAccount
      summary: Change name, and email notifications on or off
      description: >
        The caller's own name — what every entry and journal note they write is
        signed with — and whether the app may reach them by email. Push is the
        phone's, not stored. Fields left out are unchanged. An email address
        confirmed through Change email is copied onto the account by the first
        request made with a token carrying it, so it is not set here.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChangeMyAccountRequest'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Caregiver'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
  /v1/me/email:
    post:
      tags:
        - Account
      operationId: startEmailChange
      summary: Change email — Send code
      description: >
        Checks the current password, then asks for the new address, which is
        sent a code. The address does not change until the code is confirmed (in
        the app, against the identity provider); until then the old one still
        signs in and still receives everything. Sending again sends a new code.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChangeEmailRequest'
      responses:
        '204':
          description: Code sent to the new address
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/WrongPassword'
        '409':
          $ref: '#/components/responses/EmailInUse'
        '429':
          $ref: '#/components/responses/TooManyAttempts'
  /v1/me/close:
    post:
      tags:
        - Account
      operationId: closeMyAccount
      summary: Close this account? — Close account
      description: >
        Checks the password, then closes the account: the name and address are
        removed and the caller can no longer sign in, while every entry and
        journal note they wrote stays, attributed to a former caregiver. Each
        care team is left as leaving leaves it — their assignments still ahead
        are removed and any coverage schedule naming them ends today. Refused,
        naming the teams, while the caller is any care team's only admin.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CloseAccountRequest'
      responses:
        '204':
          description: Closed
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/WrongPassword'
        '409':
          description: >
            The caller is the only admin of these care teams. Promote someone
            first — or, on a team they are alone on, close it first.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SoleAdminOf'
        '429':
          $ref: '#/components/responses/TooManyAttempts'
  /v1/feedback:
    post:
      tags:
        - Account
      operationId: sendFeedback
      summary: Send feedback
      description: >
        One message to the people behind the app; nothing is kept. Sent with a
        token, it goes with the caller's name and address so a reply can come by
        email. Sent without one, it is anonymous: nothing that identifies the
        caregiver goes with it or is logged with it. The version and device go
        either way.
      security:
        - {}
        - bearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FeedbackRequest'
      responses:
        '202':
          description: Sent
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '429':
          $ref: '#/components/responses/TooManyAttempts'
  /v1/teams:
    post:
      tags:
        - Care teams
      operationId: createTeam
      summary: Create a care team; the caller becomes its first admin
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateTeamRequest'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamMembership'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
  /v1/me/invitations:
    get:
      tags:
        - Invitations
      operationId: listInvitationsForMe
      summary: Pending invitations addressed to the caller's verified email
      description: >
        Includes invitations to teams the caller already belongs to; redeeming
        one of those is refused with 409. Expired, accepted, and revoked
        invitations are not listed.
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/InvitationForMe'
        '401':
          $ref: '#/components/responses/Unauthorized'
  /v1/invitations/redeem:
    post:
      tags:
        - Invitations
      operationId: redeemInvitation
      summary: Join a care team as a caregiver, by invite code
      description: >
        Serves both accepting an invitation found under /v1/me/invitations and
        pasting a code. The code travels in the body, never the path, so it does
        not land in access logs. The caller's email is not checked against the
        invitation (Hide My Email); membership is.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RedeemInvitationRequest'
      responses:
        '200':
          description: Joined
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamMembership'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '409':
          $ref: '#/components/responses/AlreadyMember'
        '410':
          $ref: '#/components/responses/InvitationNotValid'
  /v1/teams/{teamId}/receivers:
    get:
      tags:
        - Care receivers
      operationId: listTeamReceivers
      summary: The care team's care receivers, oldest first
      description: >
        Active receivers by default, which is what Team's list and the choice of
        the active care receiver read. `status=archived` lists the archived ones
        instead, for the group of their own on Care team. Any member may call
        it.
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
        - name: status
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/ReceiverStatus'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/CareReceiver'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      tags:
        - Care receivers
      operationId: addCareReceiver
      summary: Add care receiver — Add receiver (admin only)
      description: >
        The time zone is required: every wall-clock time about this person —
        schedules, assignments, their day on Home — is read in it.
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewCareReceiver'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CareReceiver'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/receivers/{receiverId}/trackers:
    get:
      tags:
        - Trackers
      operationId: listReceiverTrackers
      summary: Every tracker of one care receiver, active and paused
      description: >
        Serves the Trackers list. All three filters are drawn from this one
        response, so their counts agree with what each shows. Sorted by name; a
        paused tracker never needs attention.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/TrackerRow'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      tags:
        - Trackers
      operationId: addTracker
      summary: Create a tracker for an active care receiver (admin only)
      description: >
        Add tracker's Create. Takes no schedules — those are written afterward
        in Edit tracker. The server assigns every field and option id.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewTracker'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackerDetail'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/trackers/{trackerId}:
    get:
      tags:
        - Trackers
      operationId: getTrackerDetail
      summary: One tracker, with what is wrong with it right now
      parameters:
        - name: trackerId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackerDetail'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    put:
      tags:
        - Trackers
      operationId: editTracker
      summary: Edit tracker's Save (admin only)
      description: >
        Name, icon, color, fields and gap commit together. Schedules are not
        part of this request; each is written on its own sheet's Save. Allowed
        on a paused tracker. Refused with 400 if `fields` leaves out an existing
        field (fields are paused, never removed), drops an existing choice
        option (options are retired, never removed), or changes an existing
        field's type (a type is fixed once the tracker exists). Turning a gap on
        while the tracker has schedules is refused with 409 unless
        `remove_schedules` is true, which removes every schedule as DELETE
        /v1/schedules/{scheduleId} would.
      parameters:
        - name: trackerId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TrackerChanges'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackerDetail'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/SchedulesOrGap'
  /v1/trackers/{trackerId}/pause:
    post:
      tags:
        - Trackers
      operationId: pauseTracker
      summary: Pause a tracker (admin only)
      description: >
        No new entries, its schedules stop generating, and its thresholds stop
        raising alerts. Occurrences still waiting in the future are deleted;
        everything logged, skipped or already unrecorded stays. Pausing a paused
        tracker changes nothing.
      parameters:
        - name: trackerId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackerDetail'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/trackers/{trackerId}/resume:
    post:
      tags:
        - Trackers
      operationId: resumeTracker
      summary: Resume a paused tracker (admin only)
      description: >
        Its schedules generate again from now, and its thresholds raise alerts
        again. Nothing is back-filled across the pause. Resuming an active
        tracker changes nothing.
      parameters:
        - name: trackerId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackerDetail'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/trackers/{trackerId}/entries:
    get:
      tags:
        - Entries
      operationId: listTrackerEntries
      summary: A tracker's entries, newest first
      description: >
        Logged, skipped and unrecorded together. Entries still to come are never
        listed — Coming up is what looks ahead. `from` and `to` are dates in the
        receiver's time zone, inclusive; without them the list runs back through
        everything, a page at a time.
      parameters:
        - name: trackerId
          in: path
          required: true
          schema:
            type: string
        - name: from
          in: query
          required: false
          schema:
            type: string
            format: date
        - name: to
          in: query
          required: false
          schema:
            type: string
            format: date
        - name: cursor
          in: query
          required: false
          schema:
            type: string
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 50
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntryPage'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      tags:
        - Entries
      operationId: addEntry
      summary: Quick log's step for a picked tracker — log ad hoc, or plan
      description: >
        Any member may call it. With `at` now or earlier it logs the care ad hoc
        and every required active field must be given. With `at` in the future
        it plans a one-off scheduled entry instead — `values` pre-fill it, a
        reading nobody has taken may be left out, and `unrecorded_alert` says
        whether the team is told if it goes unrecorded. Only active fields and
        active options are accepted. Refused with 409 on a paused tracker.
      parameters:
        - name: trackerId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewEntry'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntryDetail'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/EntryNotInState'
  /v1/trackers/{trackerId}/schedules:
    get:
      tags:
        - Schedules
      operationId: listTrackerSchedules
      summary: A tracker's schedules, readable by anyone on the team
      description: Removed schedules are not listed.
      parameters:
        - name: trackerId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/TrackerSchedule'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      tags:
        - Schedules
      operationId: addSchedule
      summary: A schedule's Save, for a new schedule (admin only)
      description: >
        Written at once, not with Edit tracker's Save. It starts today in the
        receiver's time zone, and its occurrences exist by the time this
        returns. On a tracker watched by a gap it is refused with 409 unless
        `replace_gap` is true, which turns the gap off. On a paused tracker it
        is stored but generates nothing until the tracker is resumed.
      parameters:
        - name: trackerId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewSchedule'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackerSchedule'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/SchedulesOrGap'
  /v1/schedules/{scheduleId}:
    put:
      tags:
        - Schedules
      operationId: changeSchedule
      summary: A schedule's Save, for an existing schedule (admin only)
      description: >
        Written at once. Its still-waiting future occurrences are replaced by
        ones made from the new rule, time and pre-filled values; nothing logged,
        skipped or already unrecorded moves.
      parameters:
        - name: scheduleId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ScheduleWrite'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TrackerSchedule'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    delete:
      tags:
        - Schedules
      operationId: removeSchedule
      summary: Remove this schedule? — Remove (admin only)
      description: >
        The rule and every occurrence it made that is still waiting go. Every
        entry already logged, skipped or unrecorded stays exactly where it is,
        and still names the schedule it came from. Repeating a removal is safe:
        on a schedule already removed it takes away anything still waiting again
        and returns 204, not 404.
      parameters:
        - name: scheduleId
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: No Content
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/receivers/{receiverId}/attention:
    get:
      tags:
        - Home
      operationId: listNeedsAttention
      summary: What needs attention for one care receiver, most important first
      description: >
        Worked out when it is read; nothing here is dismissed. Ordered
        unrecorded care first, then readings outside their range, then trackers
        past their gap, and never more than one item for a tracker — the one
        that matters most by that order, then the most recent. Unrecorded care
        leaves the list forty-eight hours after its scheduled time, settled or
        not. Paused trackers contribute nothing. Home asks for three; See all
        leads to the Trackers list instead of asking for more.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 50
            default: 3
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/AttentionItem'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/receivers/{receiverId}/coming-up:
    get:
      tags:
        - Home
      operationId: listComingUp
      summary: Each tracker's next scheduled entry, soonest first
      description: >
        One entry per tracker, so a dose given twice a day cannot push next
        week's appointment out of sight. Only entries whose time is still ahead;
        paused trackers have none. Home asks for three; the Coming up screen
        leaves `limit` off and gets every one. An empty list means nothing is
        scheduled ahead, and Home leaves the section out.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
        - name: limit
          in: query
          required: false
          schema:
            type: integer
            minimum: 1
            maximum: 100
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ReceiverEntry'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/receivers/{receiverId}/timeline:
    get:
      tags:
        - Home
      operationId: getDayTimeline
      summary: One day of one care receiver, in time order
      description: >
        `date` is a day in the receiver's time zone, no later than today there.
        Holds the entries logged that day, the day's skipped and unrecorded
        occurrences, and the journal notes written about it, oldest first —
        paused trackers' entries included, since they still belong to the days
        they happened on. Occurrences still to come are not listed; Coming up is
        what looks ahead. An empty `items` is the day where nothing was logged
        and nothing was expected.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
        - name: date
          in: query
          required: true
          schema:
            type: string
            format: date
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DayTimeline'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/receivers/{receiverId}/waiting:
    get:
      tags:
        - Home
      operationId: listWaitingEntries
      summary: The occurrences Quick log's picker leads with
      description: >
        Everything still unrecorded from the forty-eight hours before now,
        oldest first, then everything scheduled for the rest of today in the
        receiver's time zone, soonest first. Skipped and logged ones are settled
        and not listed; paused trackers have none.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ReceiverEntry'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/receivers/{receiverId}/journal-notes:
    post:
      tags:
        - Home
      operationId: addJournalNote
      summary: Write a journal note about this care receiver's day
      description: >
        Any member may write one. `at` is the time the note is about, and cannot
        be in the future — a note cannot be planned. Notifies nobody.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/JournalNoteWrite'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JournalNote'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/journal-notes/{noteId}:
    get:
      tags:
        - Home
      operationId: getJournalNote
      summary: One journal note
      parameters:
        - name: noteId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JournalNote'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    put:
      tags:
        - Home
      operationId: changeJournalNote
      summary: Edit journal note — Save
      description: >
        Any member may edit any note. Records who changed it last and when; the
        author stays the author. `at` still cannot be in the future.
      parameters:
        - name: noteId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/JournalNoteWrite'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JournalNote'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    delete:
      tags:
        - Home
      operationId: deleteJournalNote
      summary: Delete this note? — Delete
      description: Any member may delete any note. It is gone.
      parameters:
        - name: noteId
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: No Content
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/entries/{entryId}:
    get:
      tags:
        - Entries
      operationId: getEntry
      summary: Entry detail — one entry, in whatever state it is in
      parameters:
        - name: entryId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntryDetail'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    put:
      tags:
        - Entries
      operationId: changeEntry
      summary: Edit entry — Save, on a logged or skipped entry
      description: >
        Any member may edit any entry. Editing a skipped entry logs it: the care
        happened after all, and the caller becomes who logged it. A scheduled or
        unrecorded entry cannot be edited (409) — Log it is what records it.
        Records who changed it last and when.
      parameters:
        - name: entryId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EntryCare'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntryDetail'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/EntryNotInState'
    delete:
      tags:
        - Entries
      operationId: deleteEntry
      summary: Delete this entry? — Delete, on a logged or skipped entry
      description: >
        Any member may delete any entry. One logged ad hoc is gone (204). One
        that fulfilled a planned entry returns to waiting — scheduled, or
        unrecorded if its time has passed — with its pre-filled values back, and
        is returned (200). A scheduled or unrecorded entry cannot be deleted
        (409).
      parameters:
        - name: entryId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: The entry, waiting again
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntryDetail'
        '204':
          description: Gone
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/EntryNotInState'
  /v1/entries/{entryId}/log:
    post:
      tags:
        - Entries
      operationId: logEntry
      summary: Log it — record a scheduled or unrecorded entry
      description: >
        `occurred_at` is the run's one time, not the occurrence's; it cannot be
        in the future. Refused with 409 if somebody settled it first, or if its
        tracker is paused.
      parameters:
        - name: entryId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EntryCare'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntryDetail'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/EntryNotInState'
  /v1/entries/{entryId}/skip:
    post:
      tags:
        - Entries
      operationId: skipEntry
      summary: Skip — settle a scheduled or unrecorded entry as not happening
      description: >
        Records who skipped it and when, with an optional note saying why. Its
        time may be past or still ahead. Refused with 409 if somebody settled it
        first, or if its tracker is paused.
      parameters:
        - name: entryId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SkipEntry'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EntryDetail'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/EntryNotInState'
  /v1/tracker-templates:
    get:
      tags:
        - Trackers
      operationId: listTemplates
      summary: The tracker template catalogue
      description: >
        Ordered as Add tracker shows them. A template carries no ids for its
        fields; creating a tracker from one assigns them.
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/CatalogTemplate'
        '401':
          $ref: '#/components/responses/Unauthorized'
  /v1/teams/{teamId}:
    get:
      tags:
        - Care teams
      operationId: getTeam
      summary: One care team — its name and who is on it
      description: >
        Every caregiver on the team and the role each holds, readable by any
        member rather than admins alone. Admins first, then by name. Only the
        people on it now: what a former teammate looks like here is an open gap
        in the PRD.
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamDetail'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/teams/{teamId}/close:
    post:
      tags:
        - Care teams
      operationId: closeTeam
      summary: Close this care team? — Close team
      description: >
        Only for the last caregiver on the team. The team is archived and their
        membership ends, so nobody can reach it any longer, its receivers with
        it. Nothing recorded in it is erased; that is something support does on
        request.
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: No Content
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/NotLastCaregiver'
  /v1/teams/{teamId}/invitations:
    get:
      tags:
        - Invitations
      operationId: listTeamInvitations
      summary: The care team's pending invitations, each with its code (admin only)
      description: >
        Invitations not yet used and not yet expired, newest first. The code
        stays here to copy for as long as the invitation goes unused.
        Withdrawing one is an open gap in the PRD, so there is no way to here.
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/TeamInvitation'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      tags:
        - Invitations
      operationId: inviteCaregiver
      summary: Invite a caregiver — Create invitation (admin only)
      description: >
        Every invitation joins as a caregiver. The app sends no email; the admin
        copies the returned code and sends it themselves. Expires in fourteen
        days.
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NewInvitation'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamInvitation'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/InviteeAlreadyMember'
  /v1/teams/{teamId}/members/{userId}:
    put:
      tags:
        - Care teams
      operationId: changeRole
      summary: A caregiver — Make admin or Make caregiver (admin only)
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
        - name: userId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RoleChange'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeamMember'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/LastAdmin'
    delete:
      tags:
        - Care teams
      operationId: removeMember
      summary: Remove from this care team (admin), or Leave (yourself)
      description: >
        An admin may remove anyone; any caregiver may remove themselves, which
        is leaving. Takes the access and not the record — every entry and
        journal note they wrote stays, under their name. Their place on the
        roster goes with it: their assignments still ahead are removed and any
        coverage schedule naming them ends today; past assignments stay.
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
        - name: userId
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: No Content
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/LastAdmin'
  /v1/teams/{teamId}/my-notifications:
    get:
      tags:
        - Care teams
      operationId: getMyTeamNotifications
      summary: Team notification settings — which kinds this team sends you
      description: >
        The signed-in caregiver's own choices for this team, by kind for every
        receiver and tracker on it. All on until changed. The channels — push,
        email — are the account's, in Settings.
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotificationChoices'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    put:
      tags:
        - Care teams
      operationId: changeMyTeamNotifications
      summary: Team notification settings — turn a kind on or off
      description: Affects only the caller; nobody else on the team.
      parameters:
        - name: teamId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NotificationChoices'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/NotificationChoices'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/receivers/{receiverId}:
    get:
      tags:
        - Care receivers
      operationId: getCareReceiver
      summary: Care receiver — everything about the person that is not an entry
      description: >
        Readable by every member, archived or not. Coverage is read separately
        (on-duty, assignments, coverage-schedules).
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CareReceiverDetail'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    put:
      tags:
        - Care receivers
      operationId: changeCareReceiver
      summary: Edit care receiver — Save (admin only)
      description: >
        Changing the time zone keeps the receiver's routines at their wall-clock
        times: every future scheduled entry and assignment is re-resolved in the
        new zone. Nothing already past moves.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CareReceiverChanges'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CareReceiver'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/ReceiverArchived'
  /v1/receivers/{receiverId}/archive:
    post:
      tags:
        - Care receivers
      operationId: archiveCareReceiver
      summary: Archive this care receiver? — Archive (admin only)
      description: >
        Home, the receiver switcher and Quick log stop showing them, and nothing
        about them reminds or alerts anyone: their still-waiting future
        scheduled entries are removed and no more are made, as when a tracker is
        paused. Assignments are kept, since they remind nobody. Everything
        recorded stays readable from Team. Archiving one already archived
        returns 204.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: No Content
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/receivers/{receiverId}/restore:
    post:
      tags:
        - Care receivers
      operationId: restoreCareReceiver
      summary: Care receiver — Restore (admin only)
      description: >
        Their schedules make scheduled entries again from now on, for trackers
        that are not paused. Care that came due while they were archived is not
        made after the fact. Restoring one already active returns 204.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: No Content
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/receivers/{receiverId}/care-instructions:
    put:
      tags:
        - Care receivers
      operationId: changeCareInstructions
      summary: Edit care instructions — Save (admin only)
      description: >
        One free-form document. Records who changed it and when, which the Care
        receiver screen shows beside it. An empty body clears the instructions,
        and the screen goes back to saying none have been written.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CareInstructionsWrite'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CareReceiverDetail'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/ReceiverArchived'
  /v1/receivers/{receiverId}/emergency-contacts:
    put:
      tags:
        - Care receivers
      operationId: changeEmergencyContacts
      summary: Emergency contacts — Save (admin only)
      description: >
        The whole list, in the order it should appear, replacing the one there.
        A contact sent with its `contact_id` keeps it; one without is new; one
        left out is removed. Does not change who last changed the care
        instructions — that stamp is about the written instructions alone.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EmergencyContactsWrite'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CareReceiverDetail'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/ReceiverArchived'
  /v1/receivers/{receiverId}/on-duty:
    get:
      tags:
        - Coverage
      operationId: listOnDuty
      summary: Who is on duty for this care receiver right now
      description: >
        Every assignment covering this moment — more than one when they overlap.
        Empty when nobody is assigned, which is also every team that keeps no
        roster; Home and Care receiver then show nothing and "nobody assigned"
        respectively. A coordination signal only; it decides nothing.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Assignment'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
  /v1/receivers/{receiverId}/assignments:
    get:
      tags:
        - Coverage
      operationId: listAssignmentsAhead
      summary: The assignments ahead, soonest first
      description: >
        Every assignment that has not yet ended, made by hand or by a coverage
        schedule. Schedules are made ahead to the same rolling horizon as
        scheduled entries, so a rule's assignments appear here a few weeks out.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Assignment'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      tags:
        - Coverage
      operationId: addAssignment
      summary: An assignment — Save, for a new one (admin only)
      description: >
        One span of time one caregiver on this team is responsible for. May
        overlap others. Must end in the future and after it starts; times are
        local to the receiver.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AssignmentWrite'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Assignment'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/ReceiverArchived'
  /v1/assignments/{assignmentId}:
    put:
      tags:
        - Coverage
      operationId: changeAssignment
      summary: An assignment — Save or Hand to someone else (admin only)
      description: >
        Changes this one assignment and nothing else. One a coverage schedule
        made belongs to no rule afterward — its `coverage_schedule_id` is gone —
        so editing or removing the rule later leaves it as it is. An assignment
        that has already ended cannot be changed.
      parameters:
        - name: assignmentId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AssignmentWrite'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Assignment'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/AssignmentEndedOrArchived'
    delete:
      tags:
        - Coverage
      operationId: removeAssignment
      summary: An assignment — Remove (admin only)
      description: >
        Drops this one assignment and leaves the rule that made it exactly as it
        was; the rule does not make it again. An assignment that has already
        ended cannot be removed — it says who was responsible.
      parameters:
        - name: assignmentId
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: No Content
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/AssignmentEndedOrArchived'
  /v1/receivers/{receiverId}/coverage-schedules:
    get:
      tags:
        - Coverage
      operationId: listCoverageSchedules
      summary: The coverage schedules behind the assignments
      description: Rules not removed, ended or not. Any member may read them.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/CoverageSchedule'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      tags:
        - Coverage
      operationId: addCoverageSchedule
      summary: A coverage schedule — Save, for a new one (admin only)
      description: >-
        Starts today in the receiver's time zone, and makes its assignments
        ahead.
      parameters:
        - name: receiverId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CoverageScheduleWrite'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CoverageSchedule'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/ReceiverArchived'
  /v1/coverage-schedules/{coverageScheduleId}:
    put:
      tags:
        - Coverage
      operationId: changeCoverageSchedule
      summary: A coverage schedule — Save, for an existing one (admin only)
      description: >
        Redraws the assignments still ahead of it from the new rule, except any
        already changed by hand, which belong to no rule and stay as they are.
        Nothing past moves. An end date in the past is refused; ending it today
        is how a rotation stops now.
      parameters:
        - name: coverageScheduleId
          in: path
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CoverageScheduleWrite'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CoverageSchedule'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/ReceiverArchived'
    delete:
      tags:
        - Coverage
      operationId: removeCoverageSchedule
      summary: Remove this coverage schedule? — Remove (admin only)
      description: >
        The rule and every assignment it made that is still ahead go. Every
        assignment for a time already past stays, still saying who was
        responsible, as does any assignment changed by hand. Repeating a removal
        returns 204.
      parameters:
        - name: coverageScheduleId
          in: path
          required: true
          schema:
            type: string
      responses:
        '204':
          description: No Content
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/ReceiverArchived'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        The Cognito ID token (not the access token), validated by the API
        Gateway JWT authorizer. The API reads the caller's email and name from
        it.
  schemas:
    Health:
      type: object
      required:
        - status
        - version
        - timestamp
      properties:
        status:
          type: string
          enum:
            - ok
            - degraded
        version:
          type: string
          example: 0.1.0
        timestamp:
          type: string
          format: date-time
    Flags:
      type: object
      additionalProperties: true
      example:
        flags_demo:
          enabled: false
    Role:
      type: string
      enum:
        - admin
        - caregiver
    Caregiver:
      type: object
      required:
        - user_id
        - email
        - name
        - email_notifications
      properties:
        user_id:
          type: string
          description: Cognito sub
        email:
          type: string
          format: email
        name:
          type: string
        email_notifications:
          type: boolean
          description: Whether the app may reach this caregiver by email. On until changed.
    ChangeMyAccountRequest:
      type: object
      minProperties: 1
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 100
        email_notifications:
          type: boolean
    ChangeEmailRequest:
      type: object
      required:
        - current_password
        - new_email
      properties:
        current_password:
          type: string
          minLength: 1
        new_email:
          type: string
          format: email
    CloseAccountRequest:
      type: object
      required:
        - password
      properties:
        password:
          type: string
          minLength: 1
    SoleAdminOf:
      type: object
      required:
        - message
        - teams
      properties:
        message:
          type: string
        teams:
          type: array
          minItems: 1
          items:
            $ref: '#/components/schemas/SoleAdminTeam'
    SoleAdminTeam:
      type: object
      required:
        - team_id
        - name
        - alone
      properties:
        team_id:
          type: string
        name:
          type: string
        alone:
          type: boolean
          description: >
            The caller is the only one on this team, so there is nobody to
            promote: the team has to be closed first, from Care team.
    FeedbackRequest:
      type: object
      required:
        - kind
        - message
        - app_version
        - device
      properties:
        kind:
          type: string
          enum:
            - bug
            - suggestion
            - other
        message:
          type: string
          minLength: 1
          maxLength: 5000
        app_version:
          type: string
          maxLength: 50
          description: e.g. "1.4.0 (212)"
        device:
          type: string
          maxLength: 100
          description: e.g. "iPhone 15, iOS 26.1"
    TeamMembership:
      type: object
      required:
        - team_id
        - name
        - role
      properties:
        team_id:
          type: string
        name:
          type: string
        role:
          $ref: '#/components/schemas/Role'
    MyAccount:
      type: object
      required:
        - caregiver
        - teams
      properties:
        caregiver:
          $ref: '#/components/schemas/Caregiver'
        teams:
          type: array
          items:
            $ref: '#/components/schemas/TeamMembership'
    CreateTeamRequest:
      type: object
      required:
        - name
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 100
    InvitationForMe:
      type: object
      required:
        - code
        - team_id
        - team_name
        - invited_by_name
        - expires_at
      properties:
        code:
          type: string
        team_id:
          type: string
        team_name:
          type: string
        invited_by_name:
          type: string
          description: The inviting admin's name, or "a former caregiver"
        expires_at:
          type: string
          format: date-time
    RedeemInvitationRequest:
      type: object
      required:
        - code
      properties:
        code:
          type: string
          minLength: 1
    CareReceiver:
      type: object
      required:
        - receiver_id
        - team_id
        - name
        - time_zone
      properties:
        receiver_id:
          type: string
        team_id:
          type: string
        name:
          type: string
        time_zone:
          type: string
          description: IANA zone every wall-clock time about this receiver is read in
    TrackerStatus:
      type: string
      enum:
        - active
        - paused
    FieldKind:
      type: string
      enum:
        - number
        - text
        - boolean
        - choice
        - datetime
    FieldStatus:
      type: string
      enum:
        - active
        - paused
    ValueRange:
      type: object
      description: >
        Where a number is expected to stay. Either bound may be left open. A
        number field with no range never alerts.
      properties:
        low:
          type: number
        high:
          type: number
    ChoiceOption:
      type: object
      required:
        - option_id
        - label
        - status
      properties:
        option_id:
          type: string
        label:
          type: string
        status:
          type: string
          enum:
            - active
            - retired
    TrackerField:
      type: object
      required:
        - field_id
        - label
        - type
        - required
        - status
      properties:
        field_id:
          type: string
          description: Stable, never reused within its tracker
        label:
          type: string
        type:
          $ref: '#/components/schemas/FieldKind'
        unit:
          type: string
          description: number only
        required:
          type: boolean
        status:
          $ref: '#/components/schemas/FieldStatus'
        range:
          $ref: '#/components/schemas/ValueRange'
        multiple:
          type: boolean
          description: choice only — one answer or several
        options:
          type: array
          description: choice only. Never shrinks; options are retired instead.
          items:
            $ref: '#/components/schemas/ChoiceOption'
    ChoiceOptionWrite:
      type: object
      required:
        - label
      properties:
        option_id:
          type: string
          description: Absent for a new option
        label:
          type: string
          minLength: 1
          maxLength: 100
        status:
          type: string
          enum:
            - active
            - retired
          default: active
    TrackerFieldWrite:
      type: object
      required:
        - label
        - type
        - required
      properties:
        field_id:
          type: string
          description: Absent for a new field
        label:
          type: string
          minLength: 1
          maxLength: 100
        type:
          $ref: '#/components/schemas/FieldKind'
        unit:
          type: string
          maxLength: 20
        required:
          type: boolean
        status:
          $ref: '#/components/schemas/FieldStatus'
        range:
          $ref: '#/components/schemas/ValueRange'
        multiple:
          type: boolean
        options:
          type: array
          items:
            $ref: '#/components/schemas/ChoiceOptionWrite'
    TrackerRow:
      type: object
      required:
        - tracker_id
        - name
        - icon
        - color
        - status
        - needs_attention
      properties:
        tracker_id:
          type: string
        name:
          type: string
        icon:
          type: string
        color:
          type: string
        status:
          $ref: '#/components/schemas/TrackerStatus'
        last_logged_at:
          type: string
          format: date-time
          description: Absent when nothing has ever been logged against it
        paused_at:
          type: string
          format: date-time
        needs_attention:
          type: boolean
          description: Always false when paused
    TrackerAttention:
      type: object
      description: >
        One thing wrong with a tracker right now, worked out when it is read.
        `unrecorded` — an occurrence whose time has passed with nothing logged
        or skipped, for forty-eight hours after that time, whether or not it
        alerts anyone (`entry_id`, `occurrence_at`). `out_of_range` — a number
        field whose latest logged reading is outside its range (`entry_id`,
        `field_id`, `value`, `range`). `gap` — longer than `gap_hours` since the
        last entry, the tracker's creation, or its last resume, whichever is
        latest (`since`, `gap_hours`).
      required:
        - kind
      properties:
        kind:
          type: string
          enum:
            - unrecorded
            - out_of_range
            - gap
        entry_id:
          type: string
        occurrence_at:
          type: string
          format: date-time
        field_id:
          type: string
        value:
          type: number
        range:
          $ref: '#/components/schemas/ValueRange'
        since:
          type: string
          format: date-time
        gap_hours:
          type: integer
    TrackerDetail:
      type: object
      required:
        - tracker_id
        - receiver_id
        - team_id
        - name
        - icon
        - color
        - status
        - fields
        - schedule_count
        - attention
        - created_at
      properties:
        tracker_id:
          type: string
        receiver_id:
          type: string
        team_id:
          type: string
        name:
          type: string
        icon:
          type: string
        color:
          type: string
        status:
          $ref: '#/components/schemas/TrackerStatus'
        paused_at:
          type: string
          format: date-time
        fields:
          type: array
          description: Every field it has ever had, paused ones included, in order
          items:
            $ref: '#/components/schemas/TrackerField'
        gap_hours:
          type: integer
          description: Absent when no gap watches it. Never present alongside schedules.
        schedule_count:
          type: integer
        last_logged_at:
          type: string
          format: date-time
        attention:
          type: array
          description: Empty when nothing is wrong, and always empty when paused
          items:
            $ref: '#/components/schemas/TrackerAttention'
        created_at:
          type: string
          format: date-time
    NewTracker:
      type: object
      required:
        - name
        - icon
        - color
        - fields
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 100
        icon:
          type: string
          description: An SF Symbol name
        color:
          type: string
          pattern: ^#[0-9A-Fa-f]{6}$
        fields:
          type: array
          items:
            $ref: '#/components/schemas/TrackerFieldWrite'
        gap_hours:
          type: integer
          minimum: 1
    TrackerChanges:
      type: object
      description: >-
        Everything Edit tracker's Save commits; schedules and pausing are
        separate.
      required:
        - name
        - icon
        - color
        - fields
        - gap_hours
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 100
        icon:
          type: string
        color:
          type: string
          pattern: ^#[0-9A-Fa-f]{6}$
        fields:
          type: array
          description: >
            Every existing field by its `field_id`, in the order to show them,
            plus any new ones without one
          items:
            $ref: '#/components/schemas/TrackerFieldWrite'
        gap_hours:
          type: integer
          minimum: 1
          nullable: true
          description: null turns the gap off
        remove_schedules:
          type: boolean
          default: false
          description: Confirms that turning the gap on removes every schedule
    Weekday:
      type: string
      enum:
        - MO
        - TU
        - WE
        - TH
        - FR
        - SA
        - SU
    Recurrence:
      type: object
      description: >
        A rule, not a preset (ADR 0012). The app's choices write into it — every
        week, two weeks, month and two months are intervals of 1, 2, 4 and 8
        weeks. More frequencies can be added later without migrating data.
      required:
        - freq
        - interval
        - by_day
      properties:
        freq:
          type: string
          enum:
            - weekly
        interval:
          type: integer
          minimum: 1
        by_day:
          type: array
          minItems: 1
          uniqueItems: true
          items:
            $ref: '#/components/schemas/Weekday'
    TrackerSchedule:
      type: object
      required:
        - schedule_id
        - tracker_id
        - name
        - rule
        - time
        - starts_on
        - planned_values
        - unrecorded_alert
      properties:
        schedule_id:
          type: string
        tracker_id:
          type: string
        label:
          type: string
          description: What an admin typed; absent when left blank
        name:
          type: string
          description: The label, or a name derived from the schedule when it has none
        rule:
          $ref: '#/components/schemas/Recurrence'
        time:
          type: string
          description: Local HH:MM in the receiver's time zone
        starts_on:
          type: string
          format: date
        ends_on:
          type: string
          format: date
        planned_values:
          type: object
          description: >-
            Pre-filled values keyed by field_id; a choice is a list of
            option_ids
          additionalProperties: true
        unrecorded_alert:
          type: boolean
    ScheduleWrite:
      type: object
      required:
        - rule
        - time
        - planned_values
        - unrecorded_alert
      properties:
        label:
          type: string
          maxLength: 100
        rule:
          $ref: '#/components/schemas/Recurrence'
        time:
          type: string
          pattern: ^([01][0-9]|2[0-3]):[0-5][0-9]$
        ends_on:
          type: string
          format: date
        planned_values:
          type: object
          additionalProperties: true
        unrecorded_alert:
          type: boolean
    NewSchedule:
      type: object
      required:
        - rule
        - time
        - planned_values
        - unrecorded_alert
      properties:
        label:
          type: string
          maxLength: 100
        rule:
          $ref: '#/components/schemas/Recurrence'
        time:
          type: string
          pattern: ^([01][0-9]|2[0-3]):[0-5][0-9]$
        ends_on:
          type: string
          format: date
        planned_values:
          type: object
          additionalProperties: true
        unrecorded_alert:
          type: boolean
        replace_gap:
          type: boolean
          default: false
          description: Confirms that the first schedule turns the tracker's gap off
    EntryState:
      type: string
      description: >-
        Unrecorded is never stored; it is a scheduled entry whose time has
        passed.
      enum:
        - scheduled
        - unrecorded
        - logged
        - skipped
    Entry:
      type: object
      required:
        - entry_id
        - tracker_id
        - state
        - at
        - values
      properties:
        entry_id:
          type: string
        tracker_id:
          type: string
        state:
          $ref: '#/components/schemas/EntryState'
        at:
          type: string
          format: date-time
          description: When the care happened if logged, otherwise when it was due
        values:
          type: object
          description: Keyed by field_id; a choice is a list of option_ids
          additionalProperties: true
        note:
          type: string
        by_name:
          type: string
          description: >
            Who logged or skipped it, or "a former caregiver"; absent while
            unrecorded
        schedule_id:
          type: string
        schedule_name:
          type: string
          description: Present when it came from a schedule
    EntryPage:
      type: object
      required:
        - entries
      properties:
        entries:
          type: array
          items:
            $ref: '#/components/schemas/Entry'
        next_cursor:
          type: string
          description: Absent on the last page
    TrackerBadge:
      type: object
      description: Enough of a tracker to draw its row
      required:
        - tracker_id
        - name
        - icon
        - color
      properties:
        tracker_id:
          type: string
        name:
          type: string
        icon:
          type: string
        color:
          type: string
    ReceiverEntry:
      type: object
      description: An entry with its tracker, for lists that mix trackers
      required:
        - tracker
        - entry
      properties:
        tracker:
          $ref: '#/components/schemas/TrackerBadge'
        entry:
          $ref: '#/components/schemas/Entry'
    AttentionItem:
      type: object
      required:
        - tracker
        - attention
      properties:
        tracker:
          $ref: '#/components/schemas/TrackerBadge'
        attention:
          $ref: '#/components/schemas/TrackerAttention'
        field_label:
          type: string
          description: out_of_range only
        unit:
          type: string
          description: out_of_range only
          when the field has one: null
    JournalNote:
      type: object
      required:
        - note_id
        - receiver_id
        - at
        - body
        - author_name
        - created_at
      properties:
        note_id:
          type: string
        receiver_id:
          type: string
        at:
          type: string
          format: date-time
          description: The time it is about
        body:
          type: string
        author_name:
          type: string
          description: Who wrote it, or "a former caregiver"
        created_at:
          type: string
          format: date-time
        updated_by_name:
          type: string
          description: Who changed it last; absent if it has never been changed
        updated_at:
          type: string
          format: date-time
    JournalNoteWrite:
      type: object
      required:
        - at
        - body
      properties:
        at:
          type: string
          format: date-time
        body:
          type: string
          minLength: 1
          maxLength: 5000
    TimelineItem:
      type: object
      description: Exactly one of `entry` (with `tracker`) or `note`, as `kind` says
      required:
        - kind
        - at
      properties:
        kind:
          type: string
          enum:
            - entry
            - note
        at:
          type: string
          format: date-time
        tracker:
          $ref: '#/components/schemas/TrackerBadge'
        entry:
          $ref: '#/components/schemas/Entry'
        note:
          $ref: '#/components/schemas/JournalNote'
    DayTimeline:
      type: object
      required:
        - date
        - items
      properties:
        date:
          type: string
          format: date
        items:
          type: array
          items:
            $ref: '#/components/schemas/TimelineItem'
    OutOfRange:
      type: object
      required:
        - field_id
        - value
        - range
      properties:
        field_id:
          type: string
        value:
          type: number
        range:
          $ref: '#/components/schemas/ValueRange'
    EntryDetail:
      type: object
      description: >
        Everything Entry detail shows. `fields` is the tracker's field list, so
        the screen and Edit entry can label every value — paused fields
        included, since an old entry may hold their values.
      required:
        - entry
        - tracker
        - fields
        - planned
        - out_of_range
      properties:
        entry:
          $ref: '#/components/schemas/Entry'
        tracker:
          $ref: '#/components/schemas/TrackerBadge'
        fields:
          type: array
          items:
            $ref: '#/components/schemas/TrackerField'
        planned:
          type: boolean
          description: >
            True when it fulfils a plan — from a schedule or planned by hand —
            so deleting it leaves the occurrence waiting again rather than
            removing it
        occurrence_at:
          type: string
          format: date-time
          description: When it was due; planned entries only
        unrecorded_alert:
          type: boolean
          description: planned entries only
        settled_at:
          type: string
          format: date-time
          description: >-
            When it was logged or skipped (the act, not the care); absent while
            waiting
        updated_by_name:
          type: string
          description: Who changed it last; absent if it has never been changed
        updated_at:
          type: string
          format: date-time
        out_of_range:
          type: array
          description: >
            Each logged number outside its field's range as the range stands
            now. Empty unless logged.
          items:
            $ref: '#/components/schemas/OutOfRange'
    NewEntry:
      type: object
      required:
        - values
      properties:
        at:
          type: string
          format: date-time
          description: When the care happened, or is planned for. Absent means now.
        values:
          type: object
          description: Keyed by field_id; a choice is a list of option_ids
          additionalProperties: true
        note:
          type: string
          maxLength: 2000
        unrecorded_alert:
          type: boolean
          default: false
          description: Only when `at` is in the future
    EntryCare:
      type: object
      description: What logging or editing an entry records
      required:
        - occurred_at
        - values
      properties:
        occurred_at:
          type: string
          format: date-time
          description: Never in the future
        values:
          type: object
          description: Keyed by field_id; a choice is a list of option_ids
          additionalProperties: true
        note:
          type: string
          maxLength: 2000
    SkipEntry:
      type: object
      properties:
        note:
          type: string
          maxLength: 2000
    CatalogTemplate:
      type: object
      required:
        - template_id
        - name
        - icon
        - color
        - fields
      properties:
        template_id:
          type: string
        name:
          type: string
        icon:
          type: string
        color:
          type: string
        fields:
          type: array
          items:
            $ref: '#/components/schemas/TrackerFieldWrite'
        gap_hours:
          type: integer
    ReceiverStatus:
      type: string
      enum:
        - active
        - archived
    TeamMember:
      type: object
      required:
        - user_id
        - name
        - role
      properties:
        user_id:
          type: string
        name:
          type: string
        role:
          $ref: '#/components/schemas/Role'
    TeamDetail:
      type: object
      required:
        - team_id
        - name
        - my_role
        - members
      properties:
        team_id:
          type: string
        name:
          type: string
        my_role:
          $ref: '#/components/schemas/Role'
        members:
          type: array
          description: Admins first, then by name
          items:
            $ref: '#/components/schemas/TeamMember'
    TeamInvitation:
      type: object
      required:
        - code
        - email
        - invited_by_name
        - created_at
        - expires_at
      properties:
        code:
          type: string
          description: The invite code to copy
        email:
          type: string
          format: email
        invited_by_name:
          type: string
          description: The inviting admin's name, or "a former caregiver"
        created_at:
          type: string
          format: date-time
        expires_at:
          type: string
          format: date-time
    NewInvitation:
      type: object
      required:
        - email
      properties:
        email:
          type: string
          format: email
          maxLength: 254
    RoleChange:
      type: object
      required:
        - role
      properties:
        role:
          $ref: '#/components/schemas/Role'
    NotificationChoices:
      type: object
      description: Which kinds of reminder and alert this team sends the caller
      required:
        - reminders
        - range_alerts
        - gap_alerts
        - unrecorded_alerts
      properties:
        reminders:
          type: boolean
        range_alerts:
          type: boolean
        gap_alerts:
          type: boolean
        unrecorded_alerts:
          type: boolean
    NewCareReceiver:
      type: object
      required:
        - name
        - time_zone
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 100
        time_zone:
          type: string
          minLength: 1
          description: An IANA zone
    CareReceiverChanges:
      type: object
      required:
        - name
        - time_zone
      properties:
        name:
          type: string
          minLength: 1
          maxLength: 100
        time_zone:
          type: string
          minLength: 1
          description: An IANA zone
    CareInstructions:
      type: object
      required:
        - body
        - updated_by_name
        - updated_at
      properties:
        body:
          type: string
        updated_by_name:
          type: string
          description: Who last changed the written instructions, or "a former caregiver"
        updated_at:
          type: string
          format: date-time
    EmergencyContact:
      type: object
      required:
        - contact_id
        - name
        - relationship
        - phone
      properties:
        contact_id:
          type: string
        name:
          type: string
        relationship:
          type: string
        phone:
          type: string
          description: As the admin typed it; the app dials it
    CareReceiverDetail:
      type: object
      required:
        - receiver_id
        - team_id
        - team_name
        - name
        - time_zone
        - status
        - emergency_contacts
      properties:
        receiver_id:
          type: string
        team_id:
          type: string
        team_name:
          type: string
        name:
          type: string
        time_zone:
          type: string
        status:
          $ref: '#/components/schemas/ReceiverStatus'
        archived_by_name:
          type: string
          description: Present while archived
        archived_at:
          type: string
          format: date-time
        care_instructions:
          $ref: '#/components/schemas/CareInstructions'
        emergency_contacts:
          type: array
          description: In the order the admin set; empty when there are none
          items:
            $ref: '#/components/schemas/EmergencyContact'
    CareInstructionsWrite:
      type: object
      required:
        - body
      properties:
        body:
          type: string
          maxLength: 20000
    EmergencyContactWrite:
      type: object
      required:
        - name
        - relationship
        - phone
      properties:
        contact_id:
          type: string
          description: Keep an existing contact; omit for a new one
        name:
          type: string
          minLength: 1
          maxLength: 100
        relationship:
          type: string
          maxLength: 100
        phone:
          type: string
          minLength: 1
          maxLength: 40
    EmergencyContactsWrite:
      type: object
      required:
        - contacts
      properties:
        contacts:
          type: array
          maxItems: 20
          items:
            $ref: '#/components/schemas/EmergencyContactWrite'
    Assignment:
      type: object
      required:
        - assignment_id
        - receiver_id
        - user_id
        - caregiver_name
        - starts_local
        - ends_local
        - starts_at
        - ends_at
      properties:
        assignment_id:
          type: string
        receiver_id:
          type: string
        user_id:
          type: string
        caregiver_name:
          type: string
          description: Who is responsible, or "a former caregiver"
        starts_local:
          type: string
          description: Local YYYY-MM-DDTHH:MM in the receiver's time zone
        ends_local:
          type: string
          description: Local YYYY-MM-DDTHH:MM
        starts_at:
          type: string
          format: date-time
        ends_at:
          type: string
          format: date-time
        coverage_schedule_id:
          type: string
          description: The rule that made it; absent if made or since changed by hand
    AssignmentWrite:
      type: object
      required:
        - user_id
        - starts_local
        - ends_local
      properties:
        user_id:
          type: string
          description: A caregiver on this team now
        starts_local:
          type: string
          pattern: ^\d{4}-\d{2}-\d{2}T([01][0-9]|2[0-3]):[0-5][0-9]$
        ends_local:
          type: string
          pattern: ^\d{4}-\d{2}-\d{2}T([01][0-9]|2[0-3]):[0-5][0-9]$
    CoverageSchedule:
      type: object
      required:
        - coverage_schedule_id
        - receiver_id
        - user_id
        - caregiver_name
        - rule
        - start_time
        - end_time
        - starts_on
      properties:
        coverage_schedule_id:
          type: string
        receiver_id:
          type: string
        user_id:
          type: string
        caregiver_name:
          type: string
        rule:
          $ref: '#/components/schemas/Recurrence'
        start_time:
          type: string
          description: Local HH:MM
        end_time:
          type: string
          description: Local HH:MM; earlier than start_time means it runs past midnight
        starts_on:
          type: string
          format: date
        ends_on:
          type: string
          format: date
    CoverageScheduleWrite:
      type: object
      required:
        - user_id
        - rule
        - start_time
        - end_time
      properties:
        user_id:
          type: string
          description: A caregiver on this team now
        rule:
          $ref: '#/components/schemas/Recurrence'
        start_time:
          type: string
          pattern: ^([01][0-9]|2[0-3]):[0-5][0-9]$
        end_time:
          type: string
          pattern: ^([01][0-9]|2[0-3]):[0-5][0-9]$
        ends_on:
          type: string
          format: date
    Error:
      type: object
      required:
        - message
      properties:
        message:
          type: string
  responses:
    BadRequest:
      description: Bad request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Missing or invalid token
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: Not permitted
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    AlreadyMember:
      description: The caller already belongs to this care team
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InvitationNotValid:
      description: >
        The code is unknown, expired, already used, or revoked. One answer for
        all four, per the PRD — none of them changes what the caregiver does
        next.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    SchedulesOrGap:
      description: >
        A tracker has schedules or a gap, never both. Resend with the confirming
        flag once the admin has been told what they are about to lose.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    EntryNotInState:
      description: >
        The entry is not in a state this allows — somebody settled it first, it
        is still waiting, or its tracker is paused. Reload it and show what is
        there now.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    LastAdmin:
      description: >
        A care team always has an admin. Refused to the last one demoting
        themselves, leaving, or being removed — promote someone first.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotLastCaregiver:
      description: |
        Only the last caregiver on a care team may close it; anyone else leaves.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    InviteeAlreadyMember:
      description: |
        That address already belongs to someone on this care team.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    ReceiverArchived:
      description: >
        The care receiver is archived, and everything about them is read-only
        until an admin restores them.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    WrongPassword:
      description: The password is not right.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    EmailInUse:
      description: Another account already uses that address.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    TooManyAttempts:
      description: >
        Too many tries in a short time. The identity provider's own limit for a
        password; for feedback, a limit on the route shared by everyone sending,
        since an anonymous sender cannot be told apart. Try again later.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    AssignmentEndedOrArchived:
      description: >
        The assignment has already ended, and stays as it is: it says who was
        responsible. Or the care receiver is archived, and everything about them
        is read-only until an admin restores them.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
