openapi: 3.0.3
info:
  title: NovaTrek Check-In Service
  description: |
    Handles day-of-adventure check-in workflow including wristband assignment,
    gear pickup verification, waiver validation, and group assembly. Coordinates
    with svc-reservations for booking data, svc-safety-compliance for waiver
    status, and svc-gear-inventory for equipment assignment.
  version: 1.0.0
  contact:
    name: NovaTrek Operations Team
    email: operations@novatrek.example.com

servers:
  - url: https://api.novatrek.example.com/checkin/v1
    description: Production

security:
  - BearerAuth: []

paths:
  /check-ins:
    post:
      operationId: createCheckIn
      summary: Initiate check-in for a participant
      description: |
        Begins the check-in process for a reservation participant. Validates that
        the reservation exists (svc-reservations) and that the participant has
        a valid waiver on file (svc-safety-compliance).
      tags: [Check-Ins]
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CheckInCreate'
      responses:
        '201':
          description: Check-in initiated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CheckIn'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '409':
          description: Participant already checked in for this reservation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
    get:
      operationId: listCheckIns
      summary: List check-ins by reservation
      tags: [Check-Ins]
      parameters:
        - name: reservation_id
          in: query
          required: true
          schema:
            type: string
            format: uuid
          description: References reservation in svc-reservations
      responses:
        '200':
          description: Check-ins for the reservation
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/CheckIn'
        '401':
          $ref: '#/components/responses/Unauthorized'

  /check-ins/{check_in_id}:
    get:
      operationId: getCheckIn
      summary: Get check-in details
      tags: [Check-Ins]
      parameters:
        - $ref: '#/components/parameters/CheckInIdPath'
      responses:
        '200':
          description: Check-in details
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CheckIn'
        '404':
          $ref: '#/components/responses/NotFound'
        '401':
          $ref: '#/components/responses/Unauthorized'

  /check-ins/{check_in_id}/gear-verification:
    post:
      operationId: verifyGear
      summary: Verify gear has been picked up and fitted
      description: |
        Records that the participant has received and been fitted with required
        gear from svc-gear-inventory. Advances check-in status to GEAR_VERIFIED.
      tags: [Check-Ins]
      parameters:
        - $ref: '#/components/parameters/CheckInIdPath'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GearVerificationRequest'
      responses:
        '200':
          description: Gear verified
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CheckIn'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          description: Check-in not in valid state for gear verification
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'

  /check-ins/{check_in_id}/wristband-assignment:
    post:
      operationId: assignWristband
      summary: Assign RFID wristband to checked-in participant
      description: |
        Assigns a color-coded RFID wristband for tracking and access control
        during the adventure. Advances check-in status to WRISTBAND_ASSIGNED.
      tags: [Check-Ins]
      parameters:
        - $ref: '#/components/parameters/CheckInIdPath'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WristbandAssignmentRequest'
      responses:
        '200':
          description: Wristband assigned
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CheckIn'
        '400':
          $ref: '#/components/responses/BadRequest'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          description: Check-in not in valid state for wristband assignment
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'

components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

  parameters:
    CheckInIdPath:
      name: check_in_id
      in: path
      required: true
      schema:
        type: string
        format: uuid

  schemas:
    CheckIn:
      type: object
      required: [id, reservation_id, participant_guest_id, status, checked_in_at, checked_in_by]
      properties:
        id:
          type: string
          format: uuid
        reservation_id:
          type: string
          format: uuid
          description: References reservation in svc-reservations
        participant_guest_id:
          type: string
          format: uuid
          description: References guest in svc-guest-profiles
        status:
          $ref: '#/components/schemas/CheckInStatus'
        wristband:
          $ref: '#/components/schemas/WristbandAssignment'
        gear_verified:
          type: boolean
          default: false
        gear_items:
          type: array
          items:
            $ref: '#/components/schemas/GearItem'
        waiver_verified:
          type: boolean
          default: false
        waiver_id:
          type: string
          format: uuid
          description: References waiver in svc-safety-compliance
        checked_in_at:
          type: string
          format: date-time
        checked_in_by:
          type: string
          format: uuid
          description: Staff member who performed check-in
        completed_at:
          type: string
          format: date-time

    CheckInCreate:
      type: object
      required: [reservation_id, participant_guest_id, checked_in_by]
      properties:
        reservation_id:
          type: string
          format: uuid
        participant_guest_id:
          type: string
          format: uuid
        checked_in_by:
          type: string
          format: uuid

    CheckInStatus:
      type: string
      enum: [INITIATED, WAIVER_VERIFIED, GEAR_VERIFIED, WRISTBAND_ASSIGNED, COMPLETE]
      description: |
        INITIATED -> WAIVER_VERIFIED -> GEAR_VERIFIED -> WRISTBAND_ASSIGNED -> COMPLETE.
        Waiver verification happens automatically on check-in creation.

    WristbandAssignment:
      type: object
      required: [wristband_id, color, rfid_tag]
      properties:
        wristband_id:
          type: string
          example: "WB-2026-08-14-0342"
        color:
          type: string
          enum: [RED, BLUE, GREEN, YELLOW, ORANGE, PURPLE]
          description: Color indicates trip group for easy visual identification
        rfid_tag:
          type: string
          example: "RFID-A3F7B201"
        assigned_at:
          type: string
          format: date-time

    WristbandAssignmentRequest:
      type: object
      required: [wristband_id, color, rfid_tag]
      properties:
        wristband_id:
          type: string
        color:
          type: string
          enum: [RED, BLUE, GREEN, YELLOW, ORANGE, PURPLE]
        rfid_tag:
          type: string

    GearVerificationRequest:
      type: object
      required: [verified_by, gear_items]
      properties:
        verified_by:
          type: string
          format: uuid
          description: Staff member verifying gear fitting
        gear_items:
          type: array
          items:
            $ref: '#/components/schemas/GearItem'
        notes:
          type: string
          example: "Helmet size adjusted to medium"

    GearItem:
      type: object
      required: [gear_inventory_id, gear_type]
      properties:
        gear_inventory_id:
          type: string
          format: uuid
          description: References item in svc-gear-inventory
        gear_type:
          type: string
          example: "HELMET"
        size:
          type: string
          example: "M"
        condition_on_issue:
          type: string
          enum: [NEW, GOOD, FAIR]

    ErrorResponse:
      type: object
      required: [code, message]
      properties:
        code:
          type: string
        message:
          type: string
        details:
          type: object
          additionalProperties: true

  responses:
    BadRequest:
      description: Invalid request payload
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: Missing or invalid JWT token
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
