openapi: 3.0.3

info:
  title: SequiPay Marketplace API
  version: "1.0.0"
  description: >
    The partner-facing integration API for SequiPay — the successor to the legacy
    marketplace-API, reading SequiPay Core's data.


    ## Authentication

    Every request carries a bearer access token:

    ```
    Authorization: Bearer <access_token>
    ```

    An API Gateway Lambda authorizer validates the token on each request, resolves
    the **company** it belongs to and the **scopes** it was granted, and injects
    both into the request. It fails closed — a missing, expired, revoked, or
    malformed token is rejected with `401` before any handler runs. Tokens are
    minted by SequiPay Core (an access/refresh pair with per-module scopes); this
    API validates and reads, it does not issue tokens here.


    **Company isolation.** The company is taken from the token, never from the
    request, so a partner only ever sees its own company's data.


    **Revocation latency.** Authorizer decisions are cached at the edge for up to
    5 minutes, so a revoke or suspension takes effect within that window.


    ## Scopes

    Access is gated per route by a `module:action` scope the token must carry
    (e.g. `users:read`). A token without the required scope gets `403`. Scopes are
    granted to the credential in Core.


    ## Response shape

    Successful and handled-error responses use the legacy envelope:

    ```json
    { "status": 200, "message": "success", "data": { } }
    ```

    `status` mirrors the HTTP status; `data` is `null` on errors.

servers:
  - url: https://{apiId}.execute-api.us-west-1.amazonaws.com/{stage}
    description: Marketplace API (API Gateway, per deploy)
    variables:
      apiId:
        default: your-api-id
        description: The REST API id from the deployed stack output (ApiBaseUrl).
      stage:
        enum: [staging, live]
        default: staging

security:
  - bearerAuth: []

tags:
  - name: Health
    description: Service and auth-chain health.
  - name: Identity
    description: Token introspection — the calling credential and its scopes.
  - name: Users
    description: A company's employees.
  - name: Positions
    description: A company's positions (job titles).
  - name: Timesheets
    description: A company's timesheets and their time entries.
  - name: Locations
    description: A company's work locations.
  - name: Onboarding
    description: A company's worker verification (onboarding) steps.
  - name: Documents
    description: A company's worker documents (metadata only).

paths:
  /v1/ping:
    get:
      tags: [Health]
      summary: Authenticated health check
      operationId: getPing
      security:
        - bearerAuth: []
      description: >
        Proves the authorizer → API Gateway chain end to end. Touches no database;
        echoes back the company and scopes the authorizer resolved from the token.
        Requires a valid token but **no specific scope**.
      responses:
        "200":
          description: The token is valid; the resolved identity is echoed back.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PingResponse"
              example:
                ok: true
                companyId: "cmp_01H8X…"
                scopes: ["users:read"]
        "401":
          $ref: "#/components/responses/Unauthorized"

  /v1/me:
    get:
      tags: [Identity]
      summary: The calling credential's identity
      operationId: getMe
      security:
        - bearerAuth: []
      description: >
        Echoes back the identity the authorizer resolved from the bearer token —
        the company, the credential, the token, and the granted scopes. Touches no
        database. Requires a valid token but **no specific scope**, so a partner can
        always inspect its own credential.
      responses:
        "200":
          description: The resolved identity.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MeResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/scopes:
    get:
      tags: [Identity]
      summary: The granted scopes
      operationId: getScopes
      security:
        - bearerAuth: []
      description: >
        Returns just the scopes the token carries. Touches no database. Requires a
        valid token but **no specific scope**.
      responses:
        "200":
          description: The granted scopes.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ScopesResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/users:
    get:
      tags: [Users]
      summary: List employees
      operationId: listUsers
      security:
        - bearerAuth: []
      description: >
        Returns the authenticated company's employees, paginated. By default only
        **current** employees are returned; soft-deleted and draft employees are
        never returned.


        Requires the `users:read` scope.
      parameters:
        - name: first_name
          in: query
          description: Partial, case-insensitive match on first name.
          schema: { type: string }
          example: ali
        - name: last_name
          in: query
          description: Partial, case-insensitive match on last name.
          schema: { type: string }
        - name: full_name
          in: query
          description: Partial, case-insensitive match on the full name.
          schema: { type: string }
        - name: email
          in: query
          description: Partial, case-insensitive match on email.
          schema: { type: string }
        - name: status
          in: query
          description: >
            `active` (default) returns current employees; `inactive` returns only
            terminated employees (end date passed).
          schema:
            type: string
            enum: [active, inactive]
            default: active
        - name: onboarding_complete
          in: query
          description: >
            Filter by onboarding state. Truthy values (`1`, `true`, `yes`) return
            fully-onboarded employees; any other value returns the rest.
          schema: { type: boolean }
        - name: page
          in: query
          description: 1-based page number.
          schema: { type: integer, minimum: 1, default: 1 }
        - name: per_page
          in: query
          description: Page size (max 200).
          schema: { type: integer, minimum: 1, maximum: 200, default: 20 }
      responses:
        "200":
          description: A page of employees.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserListResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/users/{id}:
    get:
      tags: [Users]
      summary: Get one employee
      operationId: getUser
      security:
        - bearerAuth: []
      description: >
        Returns a single employee by id, scoped to the authenticated company. A
        terminated employee is reachable by id (only the default list hides them);
        soft-deleted and draft employees are not.


        Requires the `users:read` scope.
      parameters:
        - name: id
          in: path
          required: true
          description: The employee's numeric id.
          schema:
            type: integer
            format: int64
            minimum: 1
          example: 1024
      responses:
        "200":
          description: The employee.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserResponse"
        "400":
          description: The id is not a positive integer.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 400
                message: invalid user id
                data: null
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: No such employee for this company.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 404
                message: not found
                data: null
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/positions:
    get:
      tags: [Positions]
      summary: List positions
      operationId: listPositions
      security:
        - bearerAuth: []
      description: >
        Returns the authenticated company's positions, paginated. By default only
        **active** (non-archived) positions are returned; soft-deleted positions
        are never returned.


        Requires the `positions:read` scope.
      parameters:
        - name: title
          in: query
          description: Partial, case-insensitive match on the title.
          schema: { type: string }
          example: sales
        - name: default_worker_type
          in: query
          description: Exact match on the default classification (Core `default_classification`).
          schema: { type: string }
          example: w2
        - name: status
          in: query
          description: >
            `active` (default) returns non-archived positions; `archived` returns
            only archived positions; `all` returns both (never soft-deleted).
          schema:
            type: string
            enum: [active, archived, all]
            default: active
        - name: page
          in: query
          description: 1-based page number.
          schema: { type: integer, minimum: 1, default: 1 }
        - name: per_page
          in: query
          description: Page size (max 200).
          schema: { type: integer, minimum: 1, maximum: 200, default: 20 }
      responses:
        "200":
          description: A page of positions.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PositionListResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/positions/{id}:
    get:
      tags: [Positions]
      summary: Get one position
      operationId: getPosition
      security:
        - bearerAuth: []
      description: >
        Returns a single position by id, scoped to the authenticated company. An
        archived position is reachable by id (only the default list hides them);
        soft-deleted positions are not.


        Requires the `positions:read` scope.
      parameters:
        - name: id
          in: path
          required: true
          description: The position's numeric id.
          schema:
            type: integer
            format: int64
            minimum: 1
          example: 7
      responses:
        "200":
          description: The position.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/PositionResponse"
        "400":
          description: The id is not a positive integer.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 400
                message: invalid position id
                data: null
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: No such position for this company.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 404
                message: not found
                data: null
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/timesheets:
    get:
      tags: [Timesheets]
      summary: List timesheets
      operationId: listTimesheets
      security:
        - bearerAuth: []
      description: >
        Returns the authenticated company's timesheets, paginated, newest period
        first. Soft-deleted timesheets are never returned. Line items are omitted
        from the list — fetch a single timesheet for its time entries.


        Requires the `timesheets:read` scope.
      parameters:
        - name: employee_id
          in: query
          description: Exact match on the employee id.
          schema: { type: integer, format: int64, minimum: 1 }
          example: 1024
        - name: status
          in: query
          description: Exact match on the timesheet status (e.g. draft, submitted).
          schema: { type: string }
          example: submitted
        - name: from
          in: query
          description: Only timesheets whose period starts on or after this date (YYYY-MM-DD).
          schema: { type: string, format: date }
          example: "2024-01-01"
        - name: to
          in: query
          description: Only timesheets whose period starts on or before this date (YYYY-MM-DD).
          schema: { type: string, format: date }
          example: "2024-01-31"
        - name: page
          in: query
          description: 1-based page number.
          schema: { type: integer, minimum: 1, default: 1 }
        - name: per_page
          in: query
          description: Page size (max 200).
          schema: { type: integer, minimum: 1, maximum: 200, default: 20 }
      responses:
        "200":
          description: A page of timesheets.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TimesheetListResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalError"

    post:
      tags: [Timesheets]
      summary: Write a time entry
      operationId: writeTimeEntry
      security:
        - bearerAuth: []
      description: >
        Records one time entry for an employee. The write is asynchronous and
        idempotent: the service resolves the employee, forwards the entry to
        sequipay-core's single hours path, and returns 202 with a receipt id.
        Poll `GET /v1/timesheets/receipts/{id}` for the outcome.


        Idempotency is on `reference_id` — your own stable id for this entry.
        Re-sending the same `reference_id` amends the same entry and never
        duplicates it, so a 503 is always safe to retry with the same body.


        `kind` (worked vs adjustment) is NOT accepted — the service decides, based
        on whether the work date falls in a paid period.


        Requires the `timesheets:write` scope.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/TimeEntryWriteRequest"
      responses:
        "202":
          description: Accepted and queued. Poll the receipt for the outcome.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TimeEntryWriteResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: No such employee for this company.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 404
                message: employee not found for this company
                data: null
        "422":
          description: The body failed validation (this service's shape checks or Core's).
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ValidationError"
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          $ref: "#/components/responses/CoreUnavailable"

  /v1/timesheets/receipts/{id}:
    get:
      tags: [Timesheets]
      summary: Poll a write receipt
      operationId: getTimeEntryReceipt
      security:
        - bearerAuth: []
      description: >
        Returns the outcome of a `POST /v1/timesheets` write by its receipt id.
        `status` is one of: `processing` (still queued), `saved` (with `result`:
        created | amended | adjustment), `refused` (with `detail`), `locked` (the
        pay period was already paid), or `failed` (with `retriable: true` — safe to
        retry the original write on the same `reference_id`).


        Requires the `timesheets:write` scope — only a writer has receipts to poll.
      parameters:
        - name: id
          in: path
          required: true
          description: >
            The opaque receipt token returned by the write. It is bound to your
            company; a token for another company (or a malformed one) returns 404 /
            400. Treat it as an opaque string.
          schema: { type: string }
          example: "eyJjIjoiY21wXzAxSDhYIiwiciI6IjlmMWMyYTdlIn0.a1B2c3D4"
      responses:
        "200":
          description: The receipt's current outcome.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ReceiptResponse"
        "400":
          description: The receipt id is missing or malformed.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 400
                message: invalid receipt id
                data: null
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: No such receipt.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 404
                message: not found
                data: null
        "500":
          $ref: "#/components/responses/InternalError"
        "503":
          $ref: "#/components/responses/CoreUnavailable"

  /v1/timesheets/{id}:
    get:
      tags: [Timesheets]
      summary: Get one timesheet
      operationId: getTimesheet
      security:
        - bearerAuth: []
      description: >
        Returns a single timesheet by id, scoped to the authenticated company, with
        its time entries (line items, oldest work date first). Soft-deleted
        timesheets and soft-deleted entries are not returned. Compensation
        (`rate_cents`) is never included on an entry.


        Requires the `timesheets:read` scope.
      parameters:
        - name: id
          in: path
          required: true
          description: The timesheet's numeric id.
          schema:
            type: integer
            format: int64
            minimum: 1
          example: 42
      responses:
        "200":
          description: The timesheet with its time entries.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/TimesheetResponse"
        "400":
          description: The id is not a positive integer.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 400
                message: invalid timesheet id
                data: null
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: No such timesheet for this company.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 404
                message: not found
                data: null
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/locations:
    get:
      tags: [Locations]
      summary: List work locations
      operationId: listLocations
      security:
        - bearerAuth: []
      description: >
        Returns the authenticated company's work locations, paginated, ordered by
        name. Soft-deleted locations are never returned.


        Requires the `locations:read` scope.
      parameters:
        - name: name
          in: query
          description: Partial, case-insensitive match on the location name.
          schema: { type: string }
          example: warehouse
        - name: state
          in: query
          description: >
            Exact match on the 2-letter US state code (case-insensitive). Any other
            value is ignored.
          schema: { type: string, minLength: 2, maxLength: 2 }
          example: TX
        - name: page
          in: query
          description: 1-based page number.
          schema: { type: integer, minimum: 1, default: 1 }
        - name: per_page
          in: query
          description: Page size (max 200).
          schema: { type: integer, minimum: 1, maximum: 200, default: 20 }
      responses:
        "200":
          description: A page of work locations.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/LocationListResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/locations/{id}:
    get:
      tags: [Locations]
      summary: Get one work location
      operationId: getLocation
      security:
        - bearerAuth: []
      description: >
        Returns a single work location by id, scoped to the authenticated company.
        Soft-deleted locations are not returned.


        Requires the `locations:read` scope.
      parameters:
        - name: id
          in: path
          required: true
          description: The location's numeric id.
          schema:
            type: integer
            format: int64
            minimum: 1
          example: 3
      responses:
        "200":
          description: The work location.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/LocationResponse"
        "400":
          description: The id is not a positive integer.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 400
                message: invalid location id
                data: null
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: No such location for this company.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 404
                message: not found
                data: null
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/onboarding:
    get:
      tags: [Onboarding]
      summary: List verification steps
      operationId: listOnboardingSteps
      security:
        - bearerAuth: []
      description: >
        Returns the authenticated company's worker verification (onboarding) steps,
        paginated, grouped by worker then in the order they appeared. Filter by
        `employee_id` to get one worker's onboarding. Soft-deleted steps are never
        returned. Internal reviewer-identity columns are never returned.


        Requires the `onboarding:read` scope.
      parameters:
        - name: employee_id
          in: query
          description: Exact match on the employee id.
          schema: { type: integer, format: int64, minimum: 1 }
          example: 1024
        - name: state
          in: query
          description: Exact match on the step state (e.g. open, completed).
          schema: { type: string }
          example: open
        - name: kind
          in: query
          description: Exact match on the step kind (e.g. i9, w4, bank).
          schema: { type: string }
          example: i9
        - name: page
          in: query
          description: 1-based page number.
          schema: { type: integer, minimum: 1, default: 1 }
        - name: per_page
          in: query
          description: Page size (max 200).
          schema: { type: integer, minimum: 1, maximum: 200, default: 20 }
      responses:
        "200":
          description: A page of verification steps.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OnboardingListResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/onboarding/{id}:
    get:
      tags: [Onboarding]
      summary: Get one verification step
      operationId: getOnboardingStep
      security:
        - bearerAuth: []
      description: >
        Returns a single worker verification step by id, scoped to the authenticated
        company. Soft-deleted steps are not returned. Internal reviewer-identity
        columns are never returned.


        Requires the `onboarding:read` scope.
      parameters:
        - name: id
          in: path
          required: true
          description: The verification step's numeric id.
          schema:
            type: integer
            format: int64
            minimum: 1
          example: 1
      responses:
        "200":
          description: The verification step.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/OnboardingResponse"
        "400":
          description: The id is not a positive integer.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 400
                message: invalid onboarding step id
                data: null
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: No such verification step for this company.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 404
                message: not found
                data: null
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/documents:
    get:
      tags: [Documents]
      summary: List worker documents
      operationId: listDocuments
      security:
        - bearerAuth: []
      description: >
        Returns the authenticated company's worker-document records, paginated,
        grouped by worker then by document type. Filter by `employee_id` to get one
        worker's documents. Returns document METADATA only — never the document
        files, the tax/withholding election detail, or the signer's IP, and never
        owner KYC identity documents. Soft-deleted documents are never returned.


        Requires the `documents:read` scope.
      parameters:
        - name: employee_id
          in: query
          description: Exact match on the employee id.
          schema: { type: integer, format: int64, minimum: 1 }
          example: 1024
        - name: document_type
          in: query
          description: Exact match on the document type.
          schema: { type: string }
          example: w4
        - name: completed
          in: query
          description: >
            Filter by completion. Truthy values (`1`, `true`, `yes`) return only
            completed documents; falsy values return only incomplete ones.
          schema: { type: boolean }
          example: true
        - name: page
          in: query
          description: 1-based page number.
          schema: { type: integer, minimum: 1, default: 1 }
        - name: per_page
          in: query
          description: Page size (max 200).
          schema: { type: integer, minimum: 1, maximum: 200, default: 20 }
      responses:
        "200":
          description: A page of worker documents.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DocumentListResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "500":
          $ref: "#/components/responses/InternalError"

  /v1/documents/{id}:
    get:
      tags: [Documents]
      summary: Get one worker document
      operationId: getDocument
      security:
        - bearerAuth: []
      description: >
        Returns a single worker-document record by id, scoped to the authenticated
        company. Returns metadata only (never the file, election detail, or signer
        IP). Soft-deleted documents are not returned.


        Requires the `documents:read` scope.
      parameters:
        - name: id
          in: path
          required: true
          description: The document's numeric id.
          schema:
            type: integer
            format: int64
            minimum: 1
          example: 1
      responses:
        "200":
          description: The worker document.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/DocumentResponse"
        "400":
          description: The id is not a positive integer.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 400
                message: invalid document id
                data: null
        "401":
          $ref: "#/components/responses/Unauthorized"
        "403":
          $ref: "#/components/responses/Forbidden"
        "404":
          description: No such document for this company.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Error"
              example:
                status: 404
                message: not found
                data: null
        "500":
          $ref: "#/components/responses/InternalError"

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: opaque
      description: A SequiPay Core-issued access token.

  responses:
    Unauthorized:
      description: Missing, invalid, expired, or revoked token (from the authorizer).
      content:
        application/json:
          schema:
            type: object
            properties:
              message:
                type: string
                example: Unauthorized
    Forbidden:
      description: The token lacks the required scope.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ScopeError"
          example:
            error: insufficient_scope
            required: "users:read"
    InternalError:
      description: >
        An infrastructure or data error. The endpoint fails closed — a 500, never a
        partial or empty-looking result.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            status: 500
            message: internal error
            data: null
    CoreUnavailable:
      description: >
        sequipay-core could not be reached or was busy. Transient — retry with the
        SAME `reference_id`; the write is idempotent, so a retry never duplicates.
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/Error"
          example:
            status: 503
            message: core unavailable, retry
            data: null

  schemas:
    PingResponse:
      type: object
      properties:
        ok:
          type: boolean
          example: true
        companyId:
          type: string
          nullable: true
          description: The company the token belongs to.
        scopes:
          type: array
          items: { type: string }
          example: ["users:read"]

    Me:
      type: object
      description: The identity the authorizer resolved from the token.
      properties:
        company_id:
          type: string
          description: The company the token belongs to.
          example: "cmp_01H8X…"
        credential_id:
          type: string
          nullable: true
          description: The partner credential the token was minted for.
          example: "cred_01H8Y…"
        token_id:
          type: string
          nullable: true
          description: The specific token presented.
          example: "tok_01H8Z…"
        scopes:
          type: array
          items: { type: string }
          example: ["locations:read", "onboarding:read"]

    MeResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/Me" }

    ScopesData:
      type: object
      properties:
        scopes:
          type: array
          items: { type: string }
          example: ["locations:read", "onboarding:read"]

    ScopesResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/ScopesData" }

    User:
      type: object
      description: >
        A company employee. Core fields the legacy API could not back are omitted
        rather than faked; sensitive Core columns (SSN, bank, compensation) are
        never returned.
      properties:
        id: { type: integer, format: int64, example: 1024 }
        first_name: { type: string, example: Alice }
        last_name: { type: string, example: Nguyen }
        middle_name: { type: string, nullable: true, example: R }
        name_suffix: { type: string, nullable: true, example: Jr }
        email: { type: string, format: email, nullable: true, example: alice@acme.com }
        worker_type:
          type: string
          description: Employment classification (Core `classification`).
          example: w2
        dob:
          type: string
          format: date
          nullable: true
          example: "1990-05-01"
        mobile_no: { type: string, nullable: true, example: "555-0100" }
        home_address_line_1: { type: string, nullable: true, example: 1 Main St }
        home_address_line_2: { type: string, nullable: true, example: Apt 4 }
        home_address_city: { type: string, nullable: true, example: Austin }
        home_address_state: { type: string, nullable: true, example: TX }
        home_address_zip: { type: string, nullable: true, example: "78701" }
        position_id: { type: integer, format: int64, nullable: true, example: 7 }
        position_name: { type: string, nullable: true, example: Sales Rep }
        status:
          type: string
          enum: [active, inactive]
          description: Derived from the end date — `inactive` once it has passed.
        onboarding_complete:
          type: boolean
          description: True when the employee has verification steps and all are complete.
        start_date: { type: string, format: date, nullable: true, example: "2024-01-15" }
        end_date: { type: string, format: date, nullable: true, example: null }
        pay_type: { type: string, example: salary }
        created_at: { type: string, format: date-time, nullable: true, example: "2024-01-15T12:00:00.000Z" }
        updated_at: { type: string, format: date-time, nullable: true, example: "2024-06-01T09:30:00.000Z" }

    UserListData:
      type: object
      properties:
        users:
          type: array
          items: { $ref: "#/components/schemas/User" }
        current_page: { type: integer, example: 1 }
        per_page: { type: integer, example: 20 }
        total: { type: integer, example: 42 }
        last_page: { type: integer, example: 3 }
        filters:
          type: object
          description: Echoes the filters actually applied.
          additionalProperties: true
          example: { status: active }

    UserListResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/UserListData" }

    UserResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/User" }

    Position:
      type: object
      description: >
        A company position (job title). Compensation Core holds on this table
        (default salary) is never returned.
      properties:
        id: { type: integer, format: int64, example: 7 }
        title: { type: string, example: Sales Rep }
        description: { type: string, nullable: true, example: Front line sales }
        default_worker_type:
          type: string
          description: Default employment classification (Core `default_classification`).
          example: w2
        status:
          type: string
          enum: [active, archived]
          description: Derived from the archived date — `archived` once it is set.
        archived_at: { type: string, format: date-time, nullable: true, example: null }
        created_at: { type: string, format: date-time, nullable: true, example: "2024-01-15T12:00:00.000Z" }
        updated_at: { type: string, format: date-time, nullable: true, example: "2024-06-01T09:30:00.000Z" }

    PositionListData:
      type: object
      properties:
        positions:
          type: array
          items: { $ref: "#/components/schemas/Position" }
        current_page: { type: integer, example: 1 }
        per_page: { type: integer, example: 20 }
        total: { type: integer, example: 12 }
        last_page: { type: integer, example: 1 }
        filters:
          type: object
          description: Echoes the filters actually applied.
          additionalProperties: true
          example: { status: active }

    PositionListResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/PositionListData" }

    PositionResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/Position" }

    TimeEntry:
      type: object
      description: >
        A time-entry line item on a timesheet. Compensation Core holds on this table
        (`rate_cents`) is never returned.
      properties:
        id: { type: integer, format: int64, example: 5001 }
        timesheet_id: { type: integer, format: int64, example: 42 }
        employee_id: { type: integer, format: int64, example: 1024 }
        work_date: { type: string, format: date, example: "2024-01-02" }
        started_at: { type: string, format: date-time, nullable: true, example: "2024-01-02T16:00:00.000Z" }
        ended_at: { type: string, format: date-time, nullable: true, example: "2024-01-02T20:00:00.000Z" }
        minutes: { type: integer, example: 240 }
        break_minutes: { type: integer, example: 0 }
        kind: { type: string, example: worked }
        source: { type: string, example: manual }
        job_ref: { type: string, nullable: true, example: J-1001 }
        job_label: { type: string, nullable: true, example: Install }
        note: { type: string, nullable: true, example: null }
        created_at: { type: string, format: date-time, nullable: true, example: "2024-01-20T12:00:00.000Z" }
        updated_at: { type: string, format: date-time, nullable: true, example: "2024-01-20T12:00:00.000Z" }

    Timesheet:
      type: object
      description: >
        A company timesheet for one employee over a pay period. Internal reviewer
        columns (reviewer id/note) are never returned. `time_entries` is present on
        the single-timesheet response only, not in the list.
      properties:
        id: { type: integer, format: int64, example: 42 }
        employee_id: { type: integer, format: int64, example: 1024 }
        period_start: { type: string, format: date, example: "2024-01-01" }
        period_end: { type: string, format: date, example: "2024-01-14" }
        status: { type: string, example: submitted }
        note: { type: string, nullable: true, example: null }
        submitted_at: { type: string, format: date-time, nullable: true, example: "2024-01-15T12:00:00.000Z" }
        reviewed_at: { type: string, format: date-time, nullable: true, example: null }
        voided_at: { type: string, format: date-time, nullable: true, example: null }
        created_at: { type: string, format: date-time, nullable: true, example: "2024-01-20T12:00:00.000Z" }
        updated_at: { type: string, format: date-time, nullable: true, example: "2024-01-20T12:00:00.000Z" }
        time_entries:
          type: array
          description: Present only on GET /v1/timesheets/{id}.
          items: { $ref: "#/components/schemas/TimeEntry" }

    TimesheetListData:
      type: object
      properties:
        timesheets:
          type: array
          items: { $ref: "#/components/schemas/Timesheet" }
        current_page: { type: integer, example: 1 }
        per_page: { type: integer, example: 20 }
        total: { type: integer, example: 8 }
        last_page: { type: integer, example: 1 }
        filters:
          type: object
          description: Echoes the filters actually applied.
          additionalProperties: true
          example: { status: submitted }

    TimesheetListResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/TimesheetListData" }

    TimesheetResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/Timesheet" }

    TimeEntryWriteRequest:
      type: object
      required: [employee_id, reference_id, work_date]
      description: >
        A time entry to record. Provide either `minutes` or `started_at`/`ended_at`.
        `kind` is not accepted. Numeric limits (the minutes range, break and rate
        ceilings) are enforced by Core and returned as a 422 if exceeded.
      properties:
        employee_id:
          type: integer
          format: int64
          minimum: 1
          description: The employee's id (as returned by the users endpoints).
          example: 1024
        reference_id:
          type: string
          maxLength: 180
          description: >
            Your own stable id for this entry — the idempotency key. Re-sending it
            amends the same entry.
          example: "shift-2024-01-02-1024"
        work_date:
          type: string
          format: date
          description: The date worked (YYYY-MM-DD).
          example: "2024-01-02"
        started_at:
          type: string
          format: date-time
          nullable: true
          description: Shift start; provide this (with ended_at) or minutes.
          example: "2024-01-02T16:00:00Z"
        ended_at:
          type: string
          format: date-time
          nullable: true
          example: "2024-01-02T20:00:00Z"
        minutes:
          type: integer
          nullable: true
          description: Minutes worked; required when started_at is not given. May be negative for an adjustment.
          example: 240
        break_minutes:
          type: integer
          nullable: true
          example: 30
        job_ref:
          type: string
          nullable: true
          example: "J-1001"
        job_label:
          type: string
          nullable: true
          example: "Install"
        rate_cents:
          type: integer
          nullable: true
          description: Pay rate in cents, if the partner carries it.
          example: 3000
        note:
          type: string
          nullable: true
          example: "Overtime approved."

    ReceiptState:
      type: object
      description: The receipt outcome.
      properties:
        receipt_id: { type: string, description: "The opaque receipt token (same value the write returned).", example: "eyJjIjoiY21wXzAxSDhYIiwiciI6IjlmMWMyYTdlIn0.a1B2c3D4" }
        status:
          type: string
          enum: [queued, processing, saved, refused, locked, failed]
          example: processing
        result:
          type: string
          enum: [created, amended, adjustment]
          description: Present when status is saved.
        detail:
          type: string
          description: Present on saved / refused / locked / failed.
        retriable:
          type: boolean
          description: Present and true when status is failed — retry the original write.

    TimeEntryWriteResponse:
      type: object
      properties:
        status: { type: integer, example: 202 }
        message: { type: string, example: accepted }
        data:
          type: object
          properties:
            receipt_id: { type: string, description: "Opaque, company-bound receipt token — poll it at GET /v1/timesheets/receipts/{id}.", example: "eyJjIjoiY21wXzAxSDhYIiwiciI6IjlmMWMyYTdlIn0.a1B2c3D4" }
            status: { type: string, example: queued }

    ReceiptResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/ReceiptState" }

    ValidationError:
      type: object
      properties:
        status: { type: integer, example: 422 }
        message: { type: string, example: validation failed }
        data:
          type: object
          nullable: true
          description: >
            This service's field errors ({ errors: [{ field, message }] }), or Core's
            own validation body when Core rejected the entry.
          properties:
            errors:
              type: array
              items:
                type: object
                properties:
                  field: { type: string, example: work_date }
                  message: { type: string, example: "required; format YYYY-MM-DD" }

    Location:
      type: object
      description: >
        A company work location. The internal payroll-provider mapping Core holds on
        this table (`worklio_location_id`) is never returned.
      properties:
        id: { type: integer, format: int64, example: 3 }
        name: { type: string, example: Austin Warehouse }
        address_line_1: { type: string, nullable: true, example: 1 Main St }
        address_line_2: { type: string, nullable: true, example: Suite 200 }
        address_city: { type: string, nullable: true, example: Austin }
        address_state: { type: string, nullable: true, example: TX }
        address_zip: { type: string, nullable: true, example: "78701" }
        created_at: { type: string, format: date-time, nullable: true, example: "2024-01-20T12:00:00.000Z" }
        updated_at: { type: string, format: date-time, nullable: true, example: "2024-06-01T09:30:00.000Z" }

    LocationListData:
      type: object
      properties:
        locations:
          type: array
          items: { $ref: "#/components/schemas/Location" }
        current_page: { type: integer, example: 1 }
        per_page: { type: integer, example: 20 }
        total: { type: integer, example: 4 }
        last_page: { type: integer, example: 1 }
        filters:
          type: object
          description: Echoes the filters actually applied.
          additionalProperties: true
          example: { state: TX }

    LocationListResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/LocationListData" }

    LocationResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/Location" }

    OnboardingStep:
      type: object
      description: >
        A worker verification (onboarding) step. Internal reviewer-identity columns
        Core holds on this table (`handled_by`, `completed_by`,
        `completed_by_user_id`) are never returned.
      properties:
        id: { type: integer, format: int64, example: 1 }
        employee_id: { type: integer, format: int64, example: 1024 }
        kind: { type: string, example: i9 }
        state: { type: string, example: completed }
        ready:
          type: boolean
          nullable: true
          description: Whether the step is ready to act on; `null` when Core has no value.
          example: true
        first_seen_at: { type: string, format: date-time, nullable: true, example: "2024-01-01T09:00:00.000Z" }
        completed_at: { type: string, format: date-time, nullable: true, example: "2024-01-20T12:00:00.000Z" }
        created_at: { type: string, format: date-time, nullable: true, example: "2024-01-20T12:00:00.000Z" }
        updated_at: { type: string, format: date-time, nullable: true, example: "2024-01-20T12:00:00.000Z" }

    OnboardingListData:
      type: object
      properties:
        steps:
          type: array
          items: { $ref: "#/components/schemas/OnboardingStep" }
        current_page: { type: integer, example: 1 }
        per_page: { type: integer, example: 20 }
        total: { type: integer, example: 6 }
        last_page: { type: integer, example: 1 }
        filters:
          type: object
          description: Echoes the filters actually applied.
          additionalProperties: true
          example: { employee_id: "1024" }

    OnboardingListResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/OnboardingListData" }

    OnboardingResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/OnboardingStep" }

    Document:
      type: object
      description: >
        A worker-document record (metadata). Sensitive columns Core holds on this
        table (`elections`, `ip_address`) and the document files themselves are never
        returned; owner KYC identity documents are never exposed by this endpoint.
      properties:
        id: { type: integer, format: int64, example: 1 }
        employee_id: { type: integer, format: int64, example: 1024 }
        document_type: { type: string, example: w4 }
        document_version: { type: string, example: "2024" }
        signer_name: { type: string, nullable: true, example: "Jane Doe" }
        completed: { type: boolean, example: true }
        completed_at: { type: string, format: date-time, nullable: true, example: "2024-01-20T12:00:00.000Z" }
        created_at: { type: string, format: date-time, nullable: true, example: "2024-01-20T12:00:00.000Z" }
        updated_at: { type: string, format: date-time, nullable: true, example: "2024-01-20T12:00:00.000Z" }

    DocumentListData:
      type: object
      properties:
        documents:
          type: array
          items: { $ref: "#/components/schemas/Document" }
        current_page: { type: integer, example: 1 }
        per_page: { type: integer, example: 20 }
        total: { type: integer, example: 3 }
        last_page: { type: integer, example: 1 }
        filters:
          type: object
          description: Echoes the filters actually applied.
          additionalProperties: true
          example: { employee_id: "1024" }

    DocumentListResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/DocumentListData" }

    DocumentResponse:
      type: object
      properties:
        status: { type: integer, example: 200 }
        message: { type: string, example: success }
        data: { $ref: "#/components/schemas/Document" }

    ScopeError:
      type: object
      properties:
        error: { type: string, example: insufficient_scope }
        required: { type: string, example: "users:read" }

    Error:
      type: object
      properties:
        status: { type: integer, example: 500 }
        message: { type: string, example: internal error }
        data: { nullable: true, example: null }
