openapi: 3.1.0
info:
  title: Pharus API
  version: 1.0.0
  description: >-
    Pharus exposes every action in the platform as a REST endpoint. Use this API
    to

    build integrations, sync data with other systems, or back your own
    interface.


    ## Conventions


    - **Base path.** Every endpoint lives under `/api`. Paths below are shown
    after that prefix.

    - **Authentication.** Send `Authorization: Bearer <firebase-id-token>`
    together with
      `X-Org-Id: <org-id>` on every request. A few token-gated routes used during invitation
      acceptance are public.
    - **Authorization.** Each endpoint declares the minimum role required
    (member, admin, or owner),
      enforced before the request runs.
    - **Errors.** Non-2xx responses use `{ "error": { "code", "message",
    "details?" } }`, where
      `code` is a stable identifier such as `not_found`, `in_use`, `invalid_transition`,
      `validation_failed`, `forbidden`, `unauthorized`, `conflict`, or `internal_error`.
    - **Deletes return 200.** Soft deletes return the updated entity; hard
    deletes return
      `{ "deletedId": "uuid" }`. There are no 204 responses.
    - **Cursor pagination.** Unbounded reads accept
    `?cursor=<opaque>&limit=<int>` and return
      `{ "data": [...], "nextCursor": string | null }`.
    - **Bulk imports** accept `{ "rows": [...] }` and return a per-row `{ index,
    status, id? | error? }`.
servers:
  - url: /api
    description: App-relative base path
components:
  schemas: {}
  parameters: {}
paths:
  /locations:
    post:
      tags:
        - Locations
      summary: Create location
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                address:
                  type:
                    - string
                    - 'null'
                city:
                  type:
                    - string
                    - 'null'
                  maxLength: 150
                state:
                  type:
                    - string
                    - 'null'
                  maxLength: 100
                country:
                  type:
                    - string
                    - 'null'
                  minLength: 2
                  maxLength: 2
                zipCode:
                  type:
                    - string
                    - 'null'
                  maxLength: 20
                notes:
                  type:
                    - string
                    - 'null'
              required:
                - name
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  address:
                    type:
                      - string
                      - 'null'
                  city:
                    type:
                      - string
                      - 'null'
                  state:
                    type:
                      - string
                      - 'null'
                  country:
                    type:
                      - string
                      - 'null'
                  zipCode:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                        format: date-time
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                        format: date-time
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - address
                  - city
                  - state
                  - country
                  - zipCode
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    get:
      tags:
        - Locations
      summary: List locations (bounded; no pagination)
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        name:
                          type: string
                        sortOrder:
                          type: integer
                        address:
                          type:
                            - string
                            - 'null'
                        city:
                          type:
                            - string
                            - 'null'
                        state:
                          type:
                            - string
                            - 'null'
                        country:
                          type:
                            - string
                            - 'null'
                        zipCode:
                          type:
                            - string
                            - 'null'
                        notes:
                          type:
                            - string
                            - 'null'
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                              format: date-time
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                              format: date-time
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - name
                        - sortOrder
                        - address
                        - city
                        - state
                        - country
                        - zipCode
                        - notes
                        - isActive
                        - createdAt
                        - updatedAt
                required:
                  - data
  /locations/{id}:
    patch:
      tags:
        - Locations
      summary: Update location
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                address:
                  type:
                    - string
                    - 'null'
                city:
                  type:
                    - string
                    - 'null'
                  maxLength: 150
                state:
                  type:
                    - string
                    - 'null'
                  maxLength: 100
                country:
                  type:
                    - string
                    - 'null'
                  minLength: 2
                  maxLength: 2
                zipCode:
                  type:
                    - string
                    - 'null'
                  maxLength: 20
                notes:
                  type:
                    - string
                    - 'null'
                sortOrder:
                  type: integer
                  minimum: 0
                isActive:
                  type: boolean
      responses:
        '200':
          description: Updated
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  address:
                    type:
                      - string
                      - 'null'
                  city:
                    type:
                      - string
                      - 'null'
                  state:
                    type:
                      - string
                      - 'null'
                  country:
                    type:
                      - string
                      - 'null'
                  zipCode:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                        format: date-time
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                        format: date-time
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - address
                  - city
                  - state
                  - country
                  - zipCode
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    delete:
      tags:
        - Locations
      summary: Delete location (gated by in-use check)
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
        '409':
          description: In use
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /locations/{id}/in-use:
    get:
      tags:
        - Locations
      summary: Check if location is referenced anywhere
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  inUse:
                    type: boolean
                  references:
                    type: object
                    properties:
                      poCount:
                        type: integer
                      woCount:
                        type: integer
                      soCount:
                        type: integer
                      ledgerCount:
                        type: integer
                    required:
                      - poCount
                      - woCount
                      - soCount
                      - ledgerCount
                required:
                  - inUse
                  - references
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /vendors:
    post:
      tags:
        - Vendors
      summary: Create vendor
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
                address:
                  type:
                    - string
                    - 'null'
                city:
                  type:
                    - string
                    - 'null'
                state:
                  type:
                    - string
                    - 'null'
                country:
                  type:
                    - string
                    - 'null'
                  minLength: 2
                  maxLength: 2
                zipCode:
                  type:
                    - string
                    - 'null'
                term:
                  type:
                    - string
                    - 'null'
                qboId:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
              required:
                - name
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  address:
                    type:
                      - string
                      - 'null'
                  city:
                    type:
                      - string
                      - 'null'
                  state:
                    type:
                      - string
                      - 'null'
                  country:
                    type:
                      - string
                      - 'null'
                  zipCode:
                    type:
                      - string
                      - 'null'
                  term:
                    type:
                      - string
                      - 'null'
                  qboId:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - address
                  - city
                  - state
                  - country
                  - zipCode
                  - term
                  - qboId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    get:
      tags:
        - Vendors
      summary: List vendors
      parameters:
        - schema:
            type: string
            enum:
              - 'true'
              - 'false'
          required: false
          name: isActive
          in: query
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        name:
                          type: string
                        address:
                          type:
                            - string
                            - 'null'
                        city:
                          type:
                            - string
                            - 'null'
                        state:
                          type:
                            - string
                            - 'null'
                        country:
                          type:
                            - string
                            - 'null'
                        zipCode:
                          type:
                            - string
                            - 'null'
                        term:
                          type:
                            - string
                            - 'null'
                        qboId:
                          type:
                            - string
                            - 'null'
                        notes:
                          type:
                            - string
                            - 'null'
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - name
                        - address
                        - city
                        - state
                        - country
                        - zipCode
                        - term
                        - qboId
                        - notes
                        - isActive
                        - createdAt
                        - updatedAt
                required:
                  - data
  /vendors/{id}:
    patch:
      tags:
        - Vendors
      summary: Update vendor
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
                address:
                  type:
                    - string
                    - 'null'
                city:
                  type:
                    - string
                    - 'null'
                state:
                  type:
                    - string
                    - 'null'
                country:
                  type:
                    - string
                    - 'null'
                  minLength: 2
                  maxLength: 2
                zipCode:
                  type:
                    - string
                    - 'null'
                term:
                  type:
                    - string
                    - 'null'
                qboId:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  address:
                    type:
                      - string
                      - 'null'
                  city:
                    type:
                      - string
                      - 'null'
                  state:
                    type:
                      - string
                      - 'null'
                  country:
                    type:
                      - string
                      - 'null'
                  zipCode:
                    type:
                      - string
                      - 'null'
                  term:
                    type:
                      - string
                      - 'null'
                  qboId:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - address
                  - city
                  - state
                  - country
                  - zipCode
                  - term
                  - qboId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    delete:
      tags:
        - Vendors
      summary: Delete vendor
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '409':
          description: In use
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    get:
      tags:
        - Vendors
      summary: Get vendor detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  address:
                    type:
                      - string
                      - 'null'
                  city:
                    type:
                      - string
                      - 'null'
                  state:
                    type:
                      - string
                      - 'null'
                  country:
                    type:
                      - string
                      - 'null'
                  zipCode:
                    type:
                      - string
                      - 'null'
                  term:
                    type:
                      - string
                      - 'null'
                  qboId:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - address
                  - city
                  - state
                  - country
                  - zipCode
                  - term
                  - qboId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /vendors/bulk-import:
    post:
      tags:
        - Vendors
      summary: Bulk-import vendors
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rows:
                  type: array
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                        minLength: 1
                        maxLength: 255
                      address:
                        type:
                          - string
                          - 'null'
                      city:
                        type:
                          - string
                          - 'null'
                      state:
                        type:
                          - string
                          - 'null'
                      country:
                        type:
                          - string
                          - 'null'
                        minLength: 2
                        maxLength: 2
                      zipCode:
                        type:
                          - string
                          - 'null'
                      term:
                        type:
                          - string
                          - 'null'
                      qboId:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                    required:
                      - name
              required:
                - rows
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ids:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - ids
  /materials:
    post:
      tags:
        - Materials
      summary: Create material
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                code:
                  type: string
                  minLength: 1
                  maxLength: 100
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
                typeId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                notes:
                  type:
                    - string
                    - 'null'
              required:
                - code
                - name
                - typeId
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  materialCode:
                    type: string
                  name:
                    type: string
                  materialTypeId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - materialCode
                  - name
                  - materialTypeId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
    get:
      tags:
        - Materials
      summary: List materials
      parameters:
        - schema:
            type: string
            enum:
              - 'true'
              - 'false'
          required: false
          name: active
          in: query
        - schema:
            type: string
          required: false
          name: type
          in: query
        - schema:
            type: string
          required: false
          name: q
          in: query
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialCode:
                          type: string
                        name:
                          type: string
                        materialTypeId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        notes:
                          type:
                            - string
                            - 'null'
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - materialCode
                        - name
                        - materialTypeId
                        - notes
                        - isActive
                        - createdAt
                        - updatedAt
                required:
                  - data
  /materials/{id}:
    patch:
      tags:
        - Materials
      summary: Update material
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                code:
                  type: string
                  minLength: 1
                  maxLength: 100
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
                typeId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                notes:
                  type:
                    - string
                    - 'null'
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  materialCode:
                    type: string
                  name:
                    type: string
                  materialTypeId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - materialCode
                  - name
                  - materialTypeId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
    delete:
      tags:
        - Materials
      summary: Delete material
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
    get:
      tags:
        - Materials
      summary: Get material detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  materialCode:
                    type: string
                  name:
                    type: string
                  materialTypeId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - materialCode
                  - name
                  - materialTypeId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
  /materials/bulk-import:
    post:
      tags:
        - Materials
      summary: Bulk-import materials
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rows:
                  type: array
                  items:
                    type: object
                    properties:
                      code:
                        type: string
                        minLength: 1
                        maxLength: 100
                      name:
                        type: string
                        minLength: 1
                        maxLength: 255
                      typeId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      notes:
                        type:
                          - string
                          - 'null'
                    required:
                      - code
                      - name
                      - typeId
              required:
                - rows
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ids:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - ids
  /material-types:
    post:
      tags:
        - Materials
      summary: Create material type
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
              required:
                - name
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    get:
      tags:
        - Materials
      summary: List material types
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        name:
                          type: string
                        sortOrder:
                          type: integer
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - name
                        - sortOrder
                        - isActive
                        - createdAt
                required:
                  - data
  /material-types/{id}:
    patch:
      tags:
        - Materials
      summary: Update material type
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                sortOrder:
                  type: integer
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    delete:
      tags:
        - Materials
      summary: Delete material type
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '409':
          description: In use
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /material-types/{id}/in-use:
    get:
      tags:
        - Materials
      summary: Check if material type is in use
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  inUse:
                    type: boolean
                  materialCount:
                    type: integer
                  sampleMaterialIds:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - inUse
                  - materialCount
                  - sampleMaterialIds
  /skus:
    post:
      tags:
        - Products
      summary: Create SKU
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                code:
                  type: string
                  minLength: 1
                  maxLength: 100
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
                typeId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                itemsPerUnit:
                  type: integer
                  minimum: 1
                ozPerItem:
                  type:
                    - number
                    - 'null'
                qboId:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
              required:
                - code
                - name
                - typeId
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  skuCode:
                    type: string
                  name:
                    type: string
                  skuTypeId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  itemsPerUnit:
                    type: integer
                  ozPerItem:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  qboId:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - skuCode
                  - name
                  - skuTypeId
                  - itemsPerUnit
                  - ozPerItem
                  - qboId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
    get:
      tags:
        - Products
      summary: List SKUs
      parameters:
        - schema:
            type: string
            enum:
              - 'true'
              - 'false'
          required: false
          name: active
          in: query
        - schema:
            type: string
          required: false
          name: type
          in: query
        - schema:
            type: string
          required: false
          name: itemsPerUnitMin
          in: query
        - schema:
            type: string
          required: false
          name: itemsPerUnitMax
          in: query
        - schema:
            type: string
          required: false
          name: ozPerItemMin
          in: query
        - schema:
            type: string
          required: false
          name: ozPerItemMax
          in: query
        - schema:
            type: string
          required: false
          name: q
          in: query
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuCode:
                          type: string
                        name:
                          type: string
                        skuTypeId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        itemsPerUnit:
                          type: integer
                        ozPerItem:
                          anyOf:
                            - type: string
                            - type: number
                            - type: 'null'
                        qboId:
                          type:
                            - string
                            - 'null'
                        notes:
                          type:
                            - string
                            - 'null'
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - skuCode
                        - name
                        - skuTypeId
                        - itemsPerUnit
                        - ozPerItem
                        - qboId
                        - notes
                        - isActive
                        - createdAt
                        - updatedAt
                required:
                  - data
  /skus/{id}:
    patch:
      tags:
        - Products
      summary: Update SKU
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                code:
                  type: string
                  minLength: 1
                  maxLength: 100
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
                typeId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                itemsPerUnit:
                  type: integer
                  minimum: 1
                ozPerItem:
                  type:
                    - number
                    - 'null'
                qboId:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  skuCode:
                    type: string
                  name:
                    type: string
                  skuTypeId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  itemsPerUnit:
                    type: integer
                  ozPerItem:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  qboId:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - skuCode
                  - name
                  - skuTypeId
                  - itemsPerUnit
                  - ozPerItem
                  - qboId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
    delete:
      tags:
        - Products
      summary: Delete SKU
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
    get:
      tags:
        - Products
      summary: Get SKU detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  skuCode:
                    type: string
                  name:
                    type: string
                  skuTypeId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  itemsPerUnit:
                    type: integer
                  ozPerItem:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  qboId:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - skuCode
                  - name
                  - skuTypeId
                  - itemsPerUnit
                  - ozPerItem
                  - qboId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /skus/bulk-import:
    post:
      tags:
        - Products
      summary: Bulk-import SKUs
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rows:
                  type: array
                  items:
                    type: object
                    properties:
                      code:
                        type: string
                        minLength: 1
                        maxLength: 100
                      name:
                        type: string
                        minLength: 1
                        maxLength: 255
                      typeId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      itemsPerUnit:
                        type: integer
                        minimum: 1
                      ozPerItem:
                        type:
                          - number
                          - 'null'
                      qboId:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                    required:
                      - code
                      - name
                      - typeId
              required:
                - rows
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ids:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - ids
  /sku-types:
    post:
      tags:
        - Products
      summary: Create SKU type
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
              required:
                - name
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    get:
      tags:
        - Products
      summary: List SKU types
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        name:
                          type: string
                        sortOrder:
                          type: integer
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - name
                        - sortOrder
                        - isActive
                        - createdAt
                required:
                  - data
  /sku-types/{id}:
    patch:
      tags:
        - Products
      summary: Update SKU type
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                sortOrder:
                  type: integer
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    delete:
      tags:
        - Products
      summary: Delete SKU type
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '409':
          description: In use
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /sku-types/{id}/in-use:
    get:
      tags:
        - Products
      summary: Check SKU type usage
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  inUse:
                    type: boolean
                  skuCount:
                    type: integer
                  sampleSkuIds:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - inUse
                  - skuCount
                  - sampleSkuIds
  /boms:
    post:
      tags:
        - BOM
      summary: Create BOM
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                outputSkuId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      materialId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      inputSkuId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: number
                        exclusiveMinimum: 0
                    required:
                      - quantity
              required:
                - outputSkuId
                - items
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  outputSkuId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        inputSkuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - skuId
                        - materialId
                        - inputSkuId
                        - quantity
                        - createdAt
                required:
                  - outputSkuId
                  - items
    get:
      tags:
        - BOM
      summary: List SKUs with BOMs
      parameters:
        - schema:
            type: string
          required: false
          name: q
          in: query
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        outputSkuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        itemCount:
                          type: integer
                          minimum: 0
                      required:
                        - outputSkuId
                        - itemCount
                required:
                  - data
  /boms/{id}:
    patch:
      tags:
        - BOM
      summary: Replace BOM composition
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                outputSkuId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      materialId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      inputSkuId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: number
                        exclusiveMinimum: 0
                    required:
                      - quantity
              required:
                - outputSkuId
                - items
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  outputSkuId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        inputSkuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - skuId
                        - materialId
                        - inputSkuId
                        - quantity
                        - createdAt
                required:
                  - outputSkuId
                  - items
    delete:
      tags:
        - BOM
      summary: Delete BOM
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /skus/{id}/bom:
    get:
      tags:
        - BOM
      summary: Get BOM for a SKU
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  outputSkuId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        inputSkuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - skuId
                        - materialId
                        - inputSkuId
                        - quantity
                        - createdAt
                required:
                  - outputSkuId
                  - items
  /contacts:
    post:
      tags:
        - Contacts
      summary: Create contact
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                firstName:
                  type: string
                  minLength: 1
                lastName:
                  type:
                    - string
                    - 'null'
                title:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
                displayName:
                  type: string
              required:
                - firstName
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  displayName:
                    type: string
                  firstName:
                    type:
                      - string
                      - 'null'
                  lastName:
                    type:
                      - string
                      - 'null'
                  title:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - displayName
                  - firstName
                  - lastName
                  - title
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    get:
      tags:
        - Contacts
      summary: List contacts
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        displayName:
                          type: string
                        firstName:
                          type:
                            - string
                            - 'null'
                        lastName:
                          type:
                            - string
                            - 'null'
                        title:
                          type:
                            - string
                            - 'null'
                        notes:
                          type:
                            - string
                            - 'null'
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - displayName
                        - firstName
                        - lastName
                        - title
                        - notes
                        - isActive
                        - createdAt
                        - updatedAt
                required:
                  - data
  /contacts/{id}:
    patch:
      tags:
        - Contacts
      summary: Update contact
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                firstName:
                  type: string
                lastName:
                  type:
                    - string
                    - 'null'
                title:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
                displayName:
                  type: string
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  displayName:
                    type: string
                  firstName:
                    type:
                      - string
                      - 'null'
                  lastName:
                    type:
                      - string
                      - 'null'
                  title:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - displayName
                  - firstName
                  - lastName
                  - title
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    delete:
      tags:
        - Contacts
      summary: Delete contact
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    get:
      tags:
        - Contacts
      summary: Get contact detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  contact:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      displayName:
                        type: string
                      firstName:
                        type:
                          - string
                          - 'null'
                      lastName:
                        type:
                          - string
                          - 'null'
                      title:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      isActive:
                        type: boolean
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - displayName
                      - firstName
                      - lastName
                      - title
                      - notes
                      - isActive
                      - createdAt
                      - updatedAt
                  methods:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        contactId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        methodType:
                          type: string
                          enum:
                            - email
                            - phone
                        value:
                          type: string
                        label:
                          type:
                            - string
                            - 'null'
                        isPrimary:
                          type: boolean
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - contactId
                        - methodType
                        - value
                        - label
                        - isPrimary
                        - isActive
                        - createdAt
                        - updatedAt
                  links:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        contactId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        entityType:
                          type: string
                          enum:
                            - customer
                            - vendor
                            - location
                        entityId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        role:
                          type:
                            - string
                            - 'null'
                        isPrimary:
                          type: boolean
                        notes:
                          type:
                            - string
                            - 'null'
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - contactId
                        - entityType
                        - entityId
                        - role
                        - isPrimary
                        - notes
                        - isActive
                        - createdAt
                        - updatedAt
                required:
                  - contact
                  - methods
                  - links
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /contacts/{id}/methods:
    post:
      tags:
        - Contacts
      summary: Add contact method
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - email
                    - phone
                value:
                  type: string
                  minLength: 1
                label:
                  type:
                    - string
                    - 'null'
                isPrimary:
                  type: boolean
              required:
                - type
                - value
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  contactId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  methodType:
                    type: string
                    enum:
                      - email
                      - phone
                  value:
                    type: string
                  label:
                    type:
                      - string
                      - 'null'
                  isPrimary:
                    type: boolean
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - contactId
                  - methodType
                  - value
                  - label
                  - isPrimary
                  - isActive
                  - createdAt
                  - updatedAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    get:
      tags:
        - Contacts
      summary: List methods for a contact
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        contactId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        methodType:
                          type: string
                          enum:
                            - email
                            - phone
                        value:
                          type: string
                        label:
                          type:
                            - string
                            - 'null'
                        isPrimary:
                          type: boolean
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - contactId
                        - methodType
                        - value
                        - label
                        - isPrimary
                        - isActive
                        - createdAt
                        - updatedAt
                required:
                  - data
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /contact-methods/{id}:
    patch:
      tags:
        - Contacts
      summary: Update contact method
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                type:
                  type: string
                  enum:
                    - email
                    - phone
                value:
                  type: string
                label:
                  type:
                    - string
                    - 'null'
                isPrimary:
                  type: boolean
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  contactId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  methodType:
                    type: string
                    enum:
                      - email
                      - phone
                  value:
                    type: string
                  label:
                    type:
                      - string
                      - 'null'
                  isPrimary:
                    type: boolean
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - contactId
                  - methodType
                  - value
                  - label
                  - isPrimary
                  - isActive
                  - createdAt
                  - updatedAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    delete:
      tags:
        - Contacts
      summary: Delete contact method
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /contacts/{id}/links:
    post:
      tags:
        - Contacts
      summary: Link contact to entity
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                entityType:
                  type: string
                  enum:
                    - customer
                    - vendor
                entityId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                role:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
                isPrimary:
                  type: boolean
              required:
                - entityType
                - entityId
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  contactId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  entityType:
                    type: string
                    enum:
                      - customer
                      - vendor
                      - location
                  entityId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  role:
                    type:
                      - string
                      - 'null'
                  isPrimary:
                    type: boolean
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - contactId
                  - entityType
                  - entityId
                  - role
                  - isPrimary
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /contact-links/{id}:
    patch:
      tags:
        - Contacts
      summary: Update contact-entity link
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                role:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
                isPrimary:
                  type: boolean
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  contactId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  entityType:
                    type: string
                    enum:
                      - customer
                      - vendor
                      - location
                  entityId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  role:
                    type:
                      - string
                      - 'null'
                  isPrimary:
                    type: boolean
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - contactId
                  - entityType
                  - entityId
                  - role
                  - isPrimary
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    delete:
      tags:
        - Contacts
      summary: Unlink contact from entity
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /contacts/find-or-create:
    post:
      tags:
        - Contacts
      summary: Find or create contact for entity
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                firstName:
                  type: string
                  minLength: 1
                lastName:
                  type:
                    - string
                    - 'null'
                email:
                  type: string
                  format: email
                entityType:
                  type: string
                  enum:
                    - customer
                    - vendor
                entityId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                role:
                  type:
                    - string
                    - 'null'
              required:
                - firstName
                - email
                - entityType
                - entityId
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  contact:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      displayName:
                        type: string
                      firstName:
                        type:
                          - string
                          - 'null'
                      lastName:
                        type:
                          - string
                          - 'null'
                      title:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      isActive:
                        type: boolean
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - displayName
                      - firstName
                      - lastName
                      - title
                      - notes
                      - isActive
                      - createdAt
                      - updatedAt
                  method:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      contactId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      methodType:
                        type: string
                        enum:
                          - email
                          - phone
                      value:
                        type: string
                      label:
                        type:
                          - string
                          - 'null'
                      isPrimary:
                        type: boolean
                      isActive:
                        type: boolean
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - contactId
                      - methodType
                      - value
                      - label
                      - isPrimary
                      - isActive
                      - createdAt
                      - updatedAt
                  link:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      contactId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      entityType:
                        type: string
                        enum:
                          - customer
                          - vendor
                          - location
                      entityId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      role:
                        type:
                          - string
                          - 'null'
                      isPrimary:
                        type: boolean
                      notes:
                        type:
                          - string
                          - 'null'
                      isActive:
                        type: boolean
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - contactId
                      - entityType
                      - entityId
                      - role
                      - isPrimary
                      - notes
                      - isActive
                      - createdAt
                      - updatedAt
                  created:
                    type: boolean
                required:
                  - contact
                  - method
                  - link
                  - created
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /contacts/linked-to:
    get:
      tags:
        - Contacts
      summary: List contacts linked to an entity
      parameters:
        - schema:
            type: string
            enum:
              - customer
              - vendor
          required: true
          name: entityType
          in: query
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: entityId
          in: query
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        link:
                          type: object
                          properties:
                            id:
                              type: string
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            orgId:
                              type: string
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            contactId:
                              type: string
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            entityType:
                              type: string
                              enum:
                                - customer
                                - vendor
                                - location
                            entityId:
                              type: string
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            role:
                              type:
                                - string
                                - 'null'
                            isPrimary:
                              type: boolean
                            notes:
                              type:
                                - string
                                - 'null'
                            isActive:
                              type: boolean
                            createdAt:
                              anyOf:
                                - type: string
                                - type: string
                                  format: date-time
                            updatedAt:
                              anyOf:
                                - type: string
                                - type: string
                                  format: date-time
                          required:
                            - id
                            - orgId
                            - contactId
                            - entityType
                            - entityId
                            - role
                            - isPrimary
                            - notes
                            - isActive
                            - createdAt
                            - updatedAt
                        contact:
                          type: object
                          properties:
                            id:
                              type: string
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            orgId:
                              type: string
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            displayName:
                              type: string
                            firstName:
                              type:
                                - string
                                - 'null'
                            lastName:
                              type:
                                - string
                                - 'null'
                            title:
                              type:
                                - string
                                - 'null'
                            notes:
                              type:
                                - string
                                - 'null'
                            isActive:
                              type: boolean
                            createdAt:
                              anyOf:
                                - type: string
                                - type: string
                                  format: date-time
                            updatedAt:
                              anyOf:
                                - type: string
                                - type: string
                                  format: date-time
                          required:
                            - id
                            - orgId
                            - displayName
                            - firstName
                            - lastName
                            - title
                            - notes
                            - isActive
                            - createdAt
                            - updatedAt
                        methods:
                          type: array
                          items:
                            type: object
                            properties:
                              id:
                                type: string
                                pattern: >-
                                  ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                              orgId:
                                type: string
                                pattern: >-
                                  ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                              contactId:
                                type: string
                                pattern: >-
                                  ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                              methodType:
                                type: string
                                enum:
                                  - email
                                  - phone
                              value:
                                type: string
                              label:
                                type:
                                  - string
                                  - 'null'
                              isPrimary:
                                type: boolean
                              isActive:
                                type: boolean
                              createdAt:
                                anyOf:
                                  - type: string
                                  - type: string
                                    format: date-time
                              updatedAt:
                                anyOf:
                                  - type: string
                                  - type: string
                                    format: date-time
                            required:
                              - id
                              - orgId
                              - contactId
                              - methodType
                              - value
                              - label
                              - isPrimary
                              - isActive
                              - createdAt
                              - updatedAt
                      required:
                        - link
                        - contact
                        - methods
                required:
                  - data
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /materials-inventory/transfers:
    post:
      tags:
        - MaterialsInventory
      summary: Create materials transfer
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                materialId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                sourceLocationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                destinationLocationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: number
                  exclusiveMinimum: 0
                eventDate:
                  type: string
                notes:
                  type:
                    - string
                    - 'null'
              required:
                - materialId
                - sourceLocationId
                - destinationLocationId
                - quantity
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  ledgerEntry:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      code:
                        type: string
                      materialId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      locationId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      eventType:
                        type: string
                        enum:
                          - ORDER
                          - RECEIVE
                          - DEMAND
                          - ALLOCATE
                          - CONSUME
                          - TRANSFER
                          - ADJUST
                          - DISPOSE
                          - REVERSE_ORDER
                          - REVERSE_RECEIVE
                          - REVERSE_DEMAND
                          - REVERSE_ALLOCATE
                          - REVERSE_CONSUME
                          - REVERSE_TRANSFER
                      quantity:
                        anyOf:
                          - type: string
                          - type: number
                      unitCost:
                        anyOf:
                          - type: string
                          - type: number
                          - type: 'null'
                      ref:
                        type:
                          - string
                          - 'null'
                      toLocationId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      notes:
                        type:
                          - string
                          - 'null'
                      eventDate:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      sourceType:
                        type:
                          - string
                          - 'null'
                      sourceId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - code
                      - materialId
                      - locationId
                      - eventType
                      - quantity
                      - unitCost
                      - ref
                      - toLocationId
                      - notes
                      - eventDate
                      - sourceType
                      - sourceId
                      - createdAt
                  ref:
                    type: string
                required:
                  - ledgerEntry
                  - ref
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /materials-inventory/transfers/{ref}/complete:
    post:
      tags:
        - MaterialsInventory
      summary: Complete in-transit transfer
      parameters:
        - schema:
            type: string
          required: true
          name: ref
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                eventDate:
                  type: string
                notes:
                  type:
                    - string
                    - 'null'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  code:
                    type: string
                  materialId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  locationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  eventType:
                    type: string
                    enum:
                      - ORDER
                      - RECEIVE
                      - DEMAND
                      - ALLOCATE
                      - CONSUME
                      - TRANSFER
                      - ADJUST
                      - DISPOSE
                      - REVERSE_ORDER
                      - REVERSE_RECEIVE
                      - REVERSE_DEMAND
                      - REVERSE_ALLOCATE
                      - REVERSE_CONSUME
                      - REVERSE_TRANSFER
                  quantity:
                    anyOf:
                      - type: string
                      - type: number
                  unitCost:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  ref:
                    type:
                      - string
                      - 'null'
                  toLocationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  notes:
                    type:
                      - string
                      - 'null'
                  eventDate:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  sourceType:
                    type:
                      - string
                      - 'null'
                  sourceId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - code
                  - materialId
                  - locationId
                  - eventType
                  - quantity
                  - unitCost
                  - ref
                  - toLocationId
                  - notes
                  - eventDate
                  - sourceType
                  - sourceId
                  - createdAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
        '409':
          description: Already completed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /materials-inventory/adjustments:
    post:
      tags:
        - MaterialsInventory
      summary: Adjust materials inventory
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                materialId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                locationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: number
                  exclusiveMinimum: 0
                notes:
                  type:
                    - string
                    - 'null'
                eventDate:
                  type: string
              required:
                - materialId
                - locationId
                - quantity
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  code:
                    type: string
                  materialId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  locationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  eventType:
                    type: string
                    enum:
                      - ORDER
                      - RECEIVE
                      - DEMAND
                      - ALLOCATE
                      - CONSUME
                      - TRANSFER
                      - ADJUST
                      - DISPOSE
                      - REVERSE_ORDER
                      - REVERSE_RECEIVE
                      - REVERSE_DEMAND
                      - REVERSE_ALLOCATE
                      - REVERSE_CONSUME
                      - REVERSE_TRANSFER
                  quantity:
                    anyOf:
                      - type: string
                      - type: number
                  unitCost:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  ref:
                    type:
                      - string
                      - 'null'
                  toLocationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  notes:
                    type:
                      - string
                      - 'null'
                  eventDate:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  sourceType:
                    type:
                      - string
                      - 'null'
                  sourceId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - code
                  - materialId
                  - locationId
                  - eventType
                  - quantity
                  - unitCost
                  - ref
                  - toLocationId
                  - notes
                  - eventDate
                  - sourceType
                  - sourceId
                  - createdAt
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /materials-inventory/disposals:
    post:
      tags:
        - MaterialsInventory
      summary: Dispose materials inventory
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                materialId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                locationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: number
                  exclusiveMinimum: 0
                notes:
                  type:
                    - string
                    - 'null'
                eventDate:
                  type: string
              required:
                - materialId
                - locationId
                - quantity
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  code:
                    type: string
                  materialId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  locationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  eventType:
                    type: string
                    enum:
                      - ORDER
                      - RECEIVE
                      - DEMAND
                      - ALLOCATE
                      - CONSUME
                      - TRANSFER
                      - ADJUST
                      - DISPOSE
                      - REVERSE_ORDER
                      - REVERSE_RECEIVE
                      - REVERSE_DEMAND
                      - REVERSE_ALLOCATE
                      - REVERSE_CONSUME
                      - REVERSE_TRANSFER
                  quantity:
                    anyOf:
                      - type: string
                      - type: number
                  unitCost:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  ref:
                    type:
                      - string
                      - 'null'
                  toLocationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  notes:
                    type:
                      - string
                      - 'null'
                  eventDate:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  sourceType:
                    type:
                      - string
                      - 'null'
                  sourceId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - code
                  - materialId
                  - locationId
                  - eventType
                  - quantity
                  - unitCost
                  - ref
                  - toLocationId
                  - notes
                  - eventDate
                  - sourceType
                  - sourceId
                  - createdAt
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /materials-inventory/summary:
    get:
      tags:
        - MaterialsInventory
      summary: Materials summary
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: false
          name: materialId
          in: query
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: false
          name: locationId
          in: query
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        materialId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        locationId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        onHand:
                          type: string
                        onOrder:
                          type: string
                      required:
                        - materialId
                        - locationId
                        - onHand
                        - onOrder
                required:
                  - data
  /materials-inventory/ledger:
    get:
      tags:
        - MaterialsInventory
      summary: List materials ledger entries
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: false
          name: materialId
          in: query
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: false
          name: locationId
          in: query
        - schema:
            type: string
            enum:
              - ORDER
              - RECEIVE
              - DEMAND
              - ALLOCATE
              - CONSUME
              - TRANSFER
              - ADJUST
              - DISPOSE
              - REVERSE_ORDER
              - REVERSE_RECEIVE
              - REVERSE_DEMAND
              - REVERSE_ALLOCATE
              - REVERSE_CONSUME
              - REVERSE_TRANSFER
          required: false
          name: eventType
          in: query
        - schema:
            type: string
          required: false
          name: ref
          in: query
        - schema:
            type: string
          required: false
          name: dateFrom
          in: query
        - schema:
            type: string
          required: false
          name: dateTo
          in: query
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        code:
                          type: string
                        materialId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        locationId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        eventType:
                          type: string
                          enum:
                            - ORDER
                            - RECEIVE
                            - DEMAND
                            - ALLOCATE
                            - CONSUME
                            - TRANSFER
                            - ADJUST
                            - DISPOSE
                            - REVERSE_ORDER
                            - REVERSE_RECEIVE
                            - REVERSE_DEMAND
                            - REVERSE_ALLOCATE
                            - REVERSE_CONSUME
                            - REVERSE_TRANSFER
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                            - type: 'null'
                        ref:
                          type:
                            - string
                            - 'null'
                        toLocationId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        notes:
                          type:
                            - string
                            - 'null'
                        eventDate:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        sourceType:
                          type:
                            - string
                            - 'null'
                        sourceId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - code
                        - materialId
                        - locationId
                        - eventType
                        - quantity
                        - unitCost
                        - ref
                        - toLocationId
                        - notes
                        - eventDate
                        - sourceType
                        - sourceId
                        - createdAt
                required:
                  - data
  /materials-inventory/ledger/{id}:
    get:
      tags:
        - MaterialsInventory
      summary: Get ledger entry detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  code:
                    type: string
                  materialId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  locationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  eventType:
                    type: string
                    enum:
                      - ORDER
                      - RECEIVE
                      - DEMAND
                      - ALLOCATE
                      - CONSUME
                      - TRANSFER
                      - ADJUST
                      - DISPOSE
                      - REVERSE_ORDER
                      - REVERSE_RECEIVE
                      - REVERSE_DEMAND
                      - REVERSE_ALLOCATE
                      - REVERSE_CONSUME
                      - REVERSE_TRANSFER
                  quantity:
                    anyOf:
                      - type: string
                      - type: number
                  unitCost:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  ref:
                    type:
                      - string
                      - 'null'
                  toLocationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  notes:
                    type:
                      - string
                      - 'null'
                  eventDate:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  sourceType:
                    type:
                      - string
                      - 'null'
                  sourceId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - code
                  - materialId
                  - locationId
                  - eventType
                  - quantity
                  - unitCost
                  - ref
                  - toLocationId
                  - notes
                  - eventDate
                  - sourceType
                  - sourceId
                  - createdAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /finished-goods-inventory/transfers:
    post:
      tags:
        - FinishedGoodsInventory
      summary: Create FG transfer
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                skuId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                sourceLocationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                destinationLocationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: number
                  exclusiveMinimum: 0
                eventDate:
                  type: string
                notes:
                  type:
                    - string
                    - 'null'
              required:
                - skuId
                - sourceLocationId
                - destinationLocationId
                - quantity
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  ledgerEntry:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      code:
                        type: string
                      skuId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      locationId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      eventType:
                        type: string
                        enum:
                          - ORDER
                          - RECEIVE
                          - PRODUCE
                          - DEMAND
                          - ALLOCATE
                          - CONSUME
                          - TRANSFER
                          - ADJUST
                          - DISPOSE
                          - REVERSE_ORDER
                          - REVERSE_RECEIVE
                          - REVERSE_PRODUCE
                          - REVERSE_DEMAND
                          - REVERSE_ALLOCATE
                          - REVERSE_CONSUME
                          - REVERSE_TRANSFER
                      quantity:
                        anyOf:
                          - type: string
                          - type: number
                      unitCost:
                        anyOf:
                          - type: string
                          - type: number
                          - type: 'null'
                      ref:
                        type:
                          - string
                          - 'null'
                      toLocationId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      notes:
                        type:
                          - string
                          - 'null'
                      eventDate:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      sourceType:
                        type:
                          - string
                          - 'null'
                      sourceId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - code
                      - skuId
                      - locationId
                      - eventType
                      - quantity
                      - unitCost
                      - ref
                      - toLocationId
                      - notes
                      - eventDate
                      - sourceType
                      - sourceId
                      - createdAt
                  ref:
                    type: string
                required:
                  - ledgerEntry
                  - ref
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /finished-goods-inventory/transfers/{ref}/complete:
    post:
      tags:
        - FinishedGoodsInventory
      summary: Complete FG in-transit transfer
      parameters:
        - schema:
            type: string
          required: true
          name: ref
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                eventDate:
                  type: string
                notes:
                  type:
                    - string
                    - 'null'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  code:
                    type: string
                  skuId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  locationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  eventType:
                    type: string
                    enum:
                      - ORDER
                      - RECEIVE
                      - PRODUCE
                      - DEMAND
                      - ALLOCATE
                      - CONSUME
                      - TRANSFER
                      - ADJUST
                      - DISPOSE
                      - REVERSE_ORDER
                      - REVERSE_RECEIVE
                      - REVERSE_PRODUCE
                      - REVERSE_DEMAND
                      - REVERSE_ALLOCATE
                      - REVERSE_CONSUME
                      - REVERSE_TRANSFER
                  quantity:
                    anyOf:
                      - type: string
                      - type: number
                  unitCost:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  ref:
                    type:
                      - string
                      - 'null'
                  toLocationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  notes:
                    type:
                      - string
                      - 'null'
                  eventDate:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  sourceType:
                    type:
                      - string
                      - 'null'
                  sourceId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - code
                  - skuId
                  - locationId
                  - eventType
                  - quantity
                  - unitCost
                  - ref
                  - toLocationId
                  - notes
                  - eventDate
                  - sourceType
                  - sourceId
                  - createdAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
        '409':
          description: Already completed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /finished-goods-inventory/adjustments:
    post:
      tags:
        - FinishedGoodsInventory
      summary: Adjust FG inventory
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                skuId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                locationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: number
                  exclusiveMinimum: 0
                notes:
                  type:
                    - string
                    - 'null'
                eventDate:
                  type: string
              required:
                - skuId
                - locationId
                - quantity
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  code:
                    type: string
                  skuId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  locationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  eventType:
                    type: string
                    enum:
                      - ORDER
                      - RECEIVE
                      - PRODUCE
                      - DEMAND
                      - ALLOCATE
                      - CONSUME
                      - TRANSFER
                      - ADJUST
                      - DISPOSE
                      - REVERSE_ORDER
                      - REVERSE_RECEIVE
                      - REVERSE_PRODUCE
                      - REVERSE_DEMAND
                      - REVERSE_ALLOCATE
                      - REVERSE_CONSUME
                      - REVERSE_TRANSFER
                  quantity:
                    anyOf:
                      - type: string
                      - type: number
                  unitCost:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  ref:
                    type:
                      - string
                      - 'null'
                  toLocationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  notes:
                    type:
                      - string
                      - 'null'
                  eventDate:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  sourceType:
                    type:
                      - string
                      - 'null'
                  sourceId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - code
                  - skuId
                  - locationId
                  - eventType
                  - quantity
                  - unitCost
                  - ref
                  - toLocationId
                  - notes
                  - eventDate
                  - sourceType
                  - sourceId
                  - createdAt
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /finished-goods-inventory/disposals:
    post:
      tags:
        - FinishedGoodsInventory
      summary: Dispose FG inventory
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                skuId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                locationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: number
                  exclusiveMinimum: 0
                notes:
                  type:
                    - string
                    - 'null'
                eventDate:
                  type: string
              required:
                - skuId
                - locationId
                - quantity
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  code:
                    type: string
                  skuId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  locationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  eventType:
                    type: string
                    enum:
                      - ORDER
                      - RECEIVE
                      - PRODUCE
                      - DEMAND
                      - ALLOCATE
                      - CONSUME
                      - TRANSFER
                      - ADJUST
                      - DISPOSE
                      - REVERSE_ORDER
                      - REVERSE_RECEIVE
                      - REVERSE_PRODUCE
                      - REVERSE_DEMAND
                      - REVERSE_ALLOCATE
                      - REVERSE_CONSUME
                      - REVERSE_TRANSFER
                  quantity:
                    anyOf:
                      - type: string
                      - type: number
                  unitCost:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  ref:
                    type:
                      - string
                      - 'null'
                  toLocationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  notes:
                    type:
                      - string
                      - 'null'
                  eventDate:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  sourceType:
                    type:
                      - string
                      - 'null'
                  sourceId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - code
                  - skuId
                  - locationId
                  - eventType
                  - quantity
                  - unitCost
                  - ref
                  - toLocationId
                  - notes
                  - eventDate
                  - sourceType
                  - sourceId
                  - createdAt
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /finished-goods-inventory/summary:
    get:
      tags:
        - FinishedGoodsInventory
      summary: FG summary
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: false
          name: skuId
          in: query
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: false
          name: locationId
          in: query
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        locationId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        onHand:
                          type: string
                        demand:
                          type: string
                        allocated:
                          type: string
                        available:
                          type: string
                      required:
                        - skuId
                        - locationId
                        - onHand
                        - demand
                        - allocated
                        - available
                required:
                  - data
  /finished-goods-inventory/ledger:
    get:
      tags:
        - FinishedGoodsInventory
      summary: List FG ledger entries
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: false
          name: skuId
          in: query
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: false
          name: locationId
          in: query
        - schema:
            type: string
            enum:
              - ORDER
              - RECEIVE
              - PRODUCE
              - DEMAND
              - ALLOCATE
              - CONSUME
              - TRANSFER
              - ADJUST
              - DISPOSE
              - REVERSE_ORDER
              - REVERSE_RECEIVE
              - REVERSE_PRODUCE
              - REVERSE_DEMAND
              - REVERSE_ALLOCATE
              - REVERSE_CONSUME
              - REVERSE_TRANSFER
          required: false
          name: eventType
          in: query
        - schema:
            type: string
          required: false
          name: ref
          in: query
        - schema:
            type: string
          required: false
          name: dateFrom
          in: query
        - schema:
            type: string
          required: false
          name: dateTo
          in: query
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        code:
                          type: string
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        locationId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        eventType:
                          type: string
                          enum:
                            - ORDER
                            - RECEIVE
                            - PRODUCE
                            - DEMAND
                            - ALLOCATE
                            - CONSUME
                            - TRANSFER
                            - ADJUST
                            - DISPOSE
                            - REVERSE_ORDER
                            - REVERSE_RECEIVE
                            - REVERSE_PRODUCE
                            - REVERSE_DEMAND
                            - REVERSE_ALLOCATE
                            - REVERSE_CONSUME
                            - REVERSE_TRANSFER
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                            - type: 'null'
                        ref:
                          type:
                            - string
                            - 'null'
                        toLocationId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        notes:
                          type:
                            - string
                            - 'null'
                        eventDate:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        sourceType:
                          type:
                            - string
                            - 'null'
                        sourceId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - code
                        - skuId
                        - locationId
                        - eventType
                        - quantity
                        - unitCost
                        - ref
                        - toLocationId
                        - notes
                        - eventDate
                        - sourceType
                        - sourceId
                        - createdAt
                required:
                  - data
  /finished-goods-inventory/ledger/{id}:
    get:
      tags:
        - FinishedGoodsInventory
      summary: Get FG ledger entry detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  code:
                    type: string
                  skuId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  locationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  eventType:
                    type: string
                    enum:
                      - ORDER
                      - RECEIVE
                      - PRODUCE
                      - DEMAND
                      - ALLOCATE
                      - CONSUME
                      - TRANSFER
                      - ADJUST
                      - DISPOSE
                      - REVERSE_ORDER
                      - REVERSE_RECEIVE
                      - REVERSE_PRODUCE
                      - REVERSE_DEMAND
                      - REVERSE_ALLOCATE
                      - REVERSE_CONSUME
                      - REVERSE_TRANSFER
                  quantity:
                    anyOf:
                      - type: string
                      - type: number
                  unitCost:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  ref:
                    type:
                      - string
                      - 'null'
                  toLocationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  notes:
                    type:
                      - string
                      - 'null'
                  eventDate:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  sourceType:
                    type:
                      - string
                      - 'null'
                  sourceId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - code
                  - skuId
                  - locationId
                  - eventType
                  - quantity
                  - unitCost
                  - ref
                  - toLocationId
                  - notes
                  - eventDate
                  - sourceType
                  - sourceId
                  - createdAt
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /sales-orders:
    post:
      tags:
        - SalesOrders
      summary: Create sales order
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                customerId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                channelId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                status:
                  type: string
                  enum:
                    - Received
                    - Entered
                    - Shipped
                    - Invoiced
                    - Paid
                    - Rejected
                    - In-Dispute
                    - Completed
                fulfillmentStatus:
                  type: string
                  enum:
                    - Pending
                    - Partial
                    - Fulfilled
                fulfillmentLocationId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                brokerId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                brokerFeePercent:
                  type:
                    - number
                    - 'null'
                brokerFees:
                  type: number
                  minimum: 0
                fulfillmentCosts:
                  type: number
                  minimum: 0
                freightCosts:
                  type: number
                  minimum: 0
                promoCosts:
                  type: number
                  minimum: 0
                otherCosts:
                  type: number
                  minimum: 0
                mabd:
                  type: string
                notes:
                  type:
                    - string
                    - 'null'
                qboId:
                  type:
                    - string
                    - 'null'
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      skuId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: integer
                        minimum: 1
                      unitPrice:
                        type: number
                        minimum: 0
                    required:
                      - skuId
                      - quantity
              required:
                - customerId
                - channelId
                - status
                - fulfillmentStatus
                - mabd
                - items
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  salesOrder:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      customerId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      soNumber:
                        type:
                          - string
                          - 'null'
                      orderChannelId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orderStatus:
                        type: string
                        enum:
                          - Received
                          - Entered
                          - Shipped
                          - Invoiced
                          - Paid
                          - Rejected
                          - In-Dispute
                          - Completed
                      fulfillmentStatus:
                        type: string
                        enum:
                          - Pending
                          - Partial
                          - Fulfilled
                      fulfillmentLocationId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      brokerId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      brokerFeePercent:
                        anyOf:
                          - type: string
                          - type: number
                          - type: 'null'
                      brokerFees:
                        anyOf:
                          - type: string
                          - type: number
                      fulfillmentCosts:
                        anyOf:
                          - type: string
                          - type: number
                      freightCosts:
                        anyOf:
                          - type: string
                          - type: number
                      promoCosts:
                        anyOf:
                          - type: string
                          - type: number
                      otherCosts:
                        anyOf:
                          - type: string
                          - type: number
                      mabd:
                        type: string
                      placedAt:
                        type: string
                      receivedAt:
                        type:
                          - string
                          - 'null'
                      enteredAt:
                        type:
                          - string
                          - 'null'
                      shippedAt:
                        type:
                          - string
                          - 'null'
                      invoicedAt:
                        type:
                          - string
                          - 'null'
                      paidAt:
                        type:
                          - string
                          - 'null'
                      rejectedAt:
                        type:
                          - string
                          - 'null'
                      inDisputeAt:
                        type:
                          - string
                          - 'null'
                      completedAt:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      qboId:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - customerId
                      - soNumber
                      - orderChannelId
                      - orderStatus
                      - fulfillmentStatus
                      - fulfillmentLocationId
                      - brokerId
                      - brokerFeePercent
                      - brokerFees
                      - fulfillmentCosts
                      - freightCosts
                      - promoCosts
                      - otherCosts
                      - mabd
                      - placedAt
                      - receivedAt
                      - enteredAt
                      - shippedAt
                      - invoicedAt
                      - paidAt
                      - rejectedAt
                      - inDisputeAt
                      - completedAt
                      - notes
                      - qboId
                      - createdAt
                      - updatedAt
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        salesOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          type: integer
                        unitPrice:
                          anyOf:
                            - type: string
                            - type: number
                      required:
                        - id
                        - orgId
                        - salesOrderId
                        - skuId
                        - quantity
                        - unitPrice
                required:
                  - salesOrder
                  - items
    get:
      tags:
        - SalesOrders
      summary: List sales orders
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        customerId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        soNumber:
                          type:
                            - string
                            - 'null'
                        orderChannelId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orderStatus:
                          type: string
                          enum:
                            - Received
                            - Entered
                            - Shipped
                            - Invoiced
                            - Paid
                            - Rejected
                            - In-Dispute
                            - Completed
                        fulfillmentStatus:
                          type: string
                          enum:
                            - Pending
                            - Partial
                            - Fulfilled
                        fulfillmentLocationId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        brokerId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        brokerFeePercent:
                          anyOf:
                            - type: string
                            - type: number
                            - type: 'null'
                        brokerFees:
                          anyOf:
                            - type: string
                            - type: number
                        fulfillmentCosts:
                          anyOf:
                            - type: string
                            - type: number
                        freightCosts:
                          anyOf:
                            - type: string
                            - type: number
                        promoCosts:
                          anyOf:
                            - type: string
                            - type: number
                        otherCosts:
                          anyOf:
                            - type: string
                            - type: number
                        mabd:
                          type: string
                        placedAt:
                          type: string
                        receivedAt:
                          type:
                            - string
                            - 'null'
                        enteredAt:
                          type:
                            - string
                            - 'null'
                        shippedAt:
                          type:
                            - string
                            - 'null'
                        invoicedAt:
                          type:
                            - string
                            - 'null'
                        paidAt:
                          type:
                            - string
                            - 'null'
                        rejectedAt:
                          type:
                            - string
                            - 'null'
                        inDisputeAt:
                          type:
                            - string
                            - 'null'
                        completedAt:
                          type:
                            - string
                            - 'null'
                        notes:
                          type:
                            - string
                            - 'null'
                        qboId:
                          type:
                            - string
                            - 'null'
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - customerId
                        - soNumber
                        - orderChannelId
                        - orderStatus
                        - fulfillmentStatus
                        - fulfillmentLocationId
                        - brokerId
                        - brokerFeePercent
                        - brokerFees
                        - fulfillmentCosts
                        - freightCosts
                        - promoCosts
                        - otherCosts
                        - mabd
                        - placedAt
                        - receivedAt
                        - enteredAt
                        - shippedAt
                        - invoicedAt
                        - paidAt
                        - rejectedAt
                        - inDisputeAt
                        - completedAt
                        - notes
                        - qboId
                        - createdAt
                        - updatedAt
                required:
                  - data
  /sales-orders/{id}:
    patch:
      tags:
        - SalesOrders
      summary: Update sales order
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                customerId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                channelId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                status:
                  type: string
                  enum:
                    - Received
                    - Entered
                    - Shipped
                    - Invoiced
                    - Paid
                    - Rejected
                    - In-Dispute
                    - Completed
                fulfillmentStatus:
                  type: string
                  enum:
                    - Pending
                    - Partial
                    - Fulfilled
                fulfillmentLocationId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                brokerId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                brokerFeePercent:
                  type:
                    - number
                    - 'null'
                brokerFees:
                  type: number
                  minimum: 0
                fulfillmentCosts:
                  type: number
                  minimum: 0
                freightCosts:
                  type: number
                  minimum: 0
                promoCosts:
                  type: number
                  minimum: 0
                otherCosts:
                  type: number
                  minimum: 0
                mabd:
                  type: string
                notes:
                  type:
                    - string
                    - 'null'
                qboId:
                  type:
                    - string
                    - 'null'
                placedAt:
                  type: string
                receivedAt:
                  type:
                    - string
                    - 'null'
                enteredAt:
                  type:
                    - string
                    - 'null'
                shippedAt:
                  type:
                    - string
                    - 'null'
                invoicedAt:
                  type:
                    - string
                    - 'null'
                paidAt:
                  type:
                    - string
                    - 'null'
                rejectedAt:
                  type:
                    - string
                    - 'null'
                inDisputeAt:
                  type:
                    - string
                    - 'null'
                completedAt:
                  type:
                    - string
                    - 'null'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  customerId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  soNumber:
                    type:
                      - string
                      - 'null'
                  orderChannelId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orderStatus:
                    type: string
                    enum:
                      - Received
                      - Entered
                      - Shipped
                      - Invoiced
                      - Paid
                      - Rejected
                      - In-Dispute
                      - Completed
                  fulfillmentStatus:
                    type: string
                    enum:
                      - Pending
                      - Partial
                      - Fulfilled
                  fulfillmentLocationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  brokerId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  brokerFeePercent:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  brokerFees:
                    anyOf:
                      - type: string
                      - type: number
                  fulfillmentCosts:
                    anyOf:
                      - type: string
                      - type: number
                  freightCosts:
                    anyOf:
                      - type: string
                      - type: number
                  promoCosts:
                    anyOf:
                      - type: string
                      - type: number
                  otherCosts:
                    anyOf:
                      - type: string
                      - type: number
                  mabd:
                    type: string
                  placedAt:
                    type: string
                  receivedAt:
                    type:
                      - string
                      - 'null'
                  enteredAt:
                    type:
                      - string
                      - 'null'
                  shippedAt:
                    type:
                      - string
                      - 'null'
                  invoicedAt:
                    type:
                      - string
                      - 'null'
                  paidAt:
                    type:
                      - string
                      - 'null'
                  rejectedAt:
                    type:
                      - string
                      - 'null'
                  inDisputeAt:
                    type:
                      - string
                      - 'null'
                  completedAt:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  qboId:
                    type:
                      - string
                      - 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - customerId
                  - soNumber
                  - orderChannelId
                  - orderStatus
                  - fulfillmentStatus
                  - fulfillmentLocationId
                  - brokerId
                  - brokerFeePercent
                  - brokerFees
                  - fulfillmentCosts
                  - freightCosts
                  - promoCosts
                  - otherCosts
                  - mabd
                  - placedAt
                  - receivedAt
                  - enteredAt
                  - shippedAt
                  - invoicedAt
                  - paidAt
                  - rejectedAt
                  - inDisputeAt
                  - completedAt
                  - notes
                  - qboId
                  - createdAt
                  - updatedAt
    delete:
      tags:
        - SalesOrders
      summary: Delete sales order
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
    get:
      tags:
        - SalesOrders
      summary: Get sales order detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  salesOrder:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      customerId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      soNumber:
                        type:
                          - string
                          - 'null'
                      orderChannelId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orderStatus:
                        type: string
                        enum:
                          - Received
                          - Entered
                          - Shipped
                          - Invoiced
                          - Paid
                          - Rejected
                          - In-Dispute
                          - Completed
                      fulfillmentStatus:
                        type: string
                        enum:
                          - Pending
                          - Partial
                          - Fulfilled
                      fulfillmentLocationId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      brokerId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      brokerFeePercent:
                        anyOf:
                          - type: string
                          - type: number
                          - type: 'null'
                      brokerFees:
                        anyOf:
                          - type: string
                          - type: number
                      fulfillmentCosts:
                        anyOf:
                          - type: string
                          - type: number
                      freightCosts:
                        anyOf:
                          - type: string
                          - type: number
                      promoCosts:
                        anyOf:
                          - type: string
                          - type: number
                      otherCosts:
                        anyOf:
                          - type: string
                          - type: number
                      mabd:
                        type: string
                      placedAt:
                        type: string
                      receivedAt:
                        type:
                          - string
                          - 'null'
                      enteredAt:
                        type:
                          - string
                          - 'null'
                      shippedAt:
                        type:
                          - string
                          - 'null'
                      invoicedAt:
                        type:
                          - string
                          - 'null'
                      paidAt:
                        type:
                          - string
                          - 'null'
                      rejectedAt:
                        type:
                          - string
                          - 'null'
                      inDisputeAt:
                        type:
                          - string
                          - 'null'
                      completedAt:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      qboId:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - customerId
                      - soNumber
                      - orderChannelId
                      - orderStatus
                      - fulfillmentStatus
                      - fulfillmentLocationId
                      - brokerId
                      - brokerFeePercent
                      - brokerFees
                      - fulfillmentCosts
                      - freightCosts
                      - promoCosts
                      - otherCosts
                      - mabd
                      - placedAt
                      - receivedAt
                      - enteredAt
                      - shippedAt
                      - invoicedAt
                      - paidAt
                      - rejectedAt
                      - inDisputeAt
                      - completedAt
                      - notes
                      - qboId
                      - createdAt
                      - updatedAt
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        salesOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          type: integer
                        unitPrice:
                          anyOf:
                            - type: string
                            - type: number
                      required:
                        - id
                        - orgId
                        - salesOrderId
                        - skuId
                        - quantity
                        - unitPrice
                required:
                  - salesOrder
                  - items
  /sales-orders/bulk-import:
    post:
      tags:
        - SalesOrders
      summary: Bulk-import sales orders
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rows:
                  type: array
                  items:
                    type: object
                    properties:
                      customerId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      channelId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      status:
                        type: string
                        enum:
                          - Received
                          - Entered
                          - Shipped
                          - Invoiced
                          - Paid
                          - Rejected
                          - In-Dispute
                          - Completed
                      fulfillmentStatus:
                        type: string
                        enum:
                          - Pending
                          - Partial
                          - Fulfilled
                      fulfillmentLocationId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      brokerId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      brokerFeePercent:
                        type:
                          - number
                          - 'null'
                      brokerFees:
                        type: number
                        minimum: 0
                      fulfillmentCosts:
                        type: number
                        minimum: 0
                      freightCosts:
                        type: number
                        minimum: 0
                      promoCosts:
                        type: number
                        minimum: 0
                      otherCosts:
                        type: number
                        minimum: 0
                      mabd:
                        type: string
                      notes:
                        type:
                          - string
                          - 'null'
                      qboId:
                        type:
                          - string
                          - 'null'
                      items:
                        type: array
                        items:
                          type: object
                          properties:
                            skuId:
                              type: string
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            quantity:
                              type: integer
                              minimum: 1
                            unitPrice:
                              type: number
                              minimum: 0
                          required:
                            - skuId
                            - quantity
                    required:
                      - customerId
                      - channelId
                      - status
                      - fulfillmentStatus
                      - mabd
                      - items
              required:
                - rows
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ids:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - ids
  /sales-orders/{id}/items:
    post:
      tags:
        - SalesOrders
      summary: Add item to sales order
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                skuId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: integer
                  minimum: 1
                unitPrice:
                  type: number
                  minimum: 0
              required:
                - skuId
                - quantity
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  salesOrderId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  skuId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  quantity:
                    type: integer
                  unitPrice:
                    anyOf:
                      - type: string
                      - type: number
                required:
                  - id
                  - orgId
                  - salesOrderId
                  - skuId
                  - quantity
                  - unitPrice
    get:
      tags:
        - SalesOrders
      summary: List sales order items
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        salesOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          type: integer
                        unitPrice:
                          anyOf:
                            - type: string
                            - type: number
                      required:
                        - id
                        - orgId
                        - salesOrderId
                        - skuId
                        - quantity
                        - unitPrice
                required:
                  - data
  /sales-order-items/{id}:
    patch:
      tags:
        - SalesOrders
      summary: Update sales order item
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                skuId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: integer
                  minimum: 1
                unitPrice:
                  type: number
                  minimum: 0
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  salesOrderId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  skuId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  quantity:
                    type: integer
                  unitPrice:
                    anyOf:
                      - type: string
                      - type: number
                required:
                  - id
                  - orgId
                  - salesOrderId
                  - skuId
                  - quantity
                  - unitPrice
    delete:
      tags:
        - SalesOrders
      summary: Remove item from sales order
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
  /sales-orders/{id}/timeline-notes:
    post:
      tags:
        - SalesOrders
      summary: Add timeline note
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                body:
                  type: string
                  minLength: 1
                statusAtTime:
                  type: string
                  enum:
                    - Received
                    - Entered
                    - Shipped
                    - Invoiced
                    - Paid
                    - Rejected
                    - In-Dispute
                    - Completed
              required:
                - body
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  salesOrderId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orderStatus:
                    type: string
                    enum:
                      - Received
                      - Entered
                      - Shipped
                      - Invoiced
                      - Paid
                      - Rejected
                      - In-Dispute
                      - Completed
                  note:
                    type: string
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - salesOrderId
                  - orderStatus
                  - note
                  - createdAt
    get:
      tags:
        - SalesOrders
      summary: List sales order timeline notes
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        salesOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orderStatus:
                          type: string
                          enum:
                            - Received
                            - Entered
                            - Shipped
                            - Invoiced
                            - Paid
                            - Rejected
                            - In-Dispute
                            - Completed
                        note:
                          type: string
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - salesOrderId
                        - orderStatus
                        - note
                        - createdAt
                required:
                  - data
  /sales-order-timeline-notes/{id}:
    delete:
      tags:
        - SalesOrders
      summary: Delete timeline note
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
  /order-channels:
    post:
      tags:
        - SalesOrders
      summary: Create order channel
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
              required:
                - name
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    get:
      tags:
        - SalesOrders
      summary: List order channels
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        name:
                          type: string
                        sortOrder:
                          type: integer
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - name
                        - sortOrder
                        - isActive
                        - createdAt
                required:
                  - data
  /order-channels/{id}:
    patch:
      tags:
        - SalesOrders
      summary: Update order channel
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                sortOrder:
                  type: integer
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    delete:
      tags:
        - SalesOrders
      summary: Delete order channel
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '409':
          description: In use
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /order-channels/{id}/reactivate:
    post:
      tags:
        - SalesOrders
      summary: Reactivate order channel
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
  /order-channels/{id}/in-use:
    get:
      tags:
        - SalesOrders
      summary: Check order channel usage
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  inUse:
                    type: boolean
                  soCount:
                    type: integer
                required:
                  - inUse
                  - soCount
  /order-status-types:
    get:
      tags:
        - SalesOrders
      summary: List order status enum values
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: string
                required:
                  - data
  /fulfillment-status-types:
    get:
      tags:
        - SalesOrders
      summary: List fulfillment status enum values
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: string
                required:
                  - data
  /purchase-orders:
    post:
      tags:
        - PurchaseOrders
      summary: Create PO
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                vendorId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                targetType:
                  type: string
                  enum:
                    - materials
                    - finished_goods
                status:
                  type: string
                  enum:
                    - Planning
                    - Placed
                    - In Transit
                    - Partial
                    - Received
                    - Paid
                    - Cancelled
                shipToLocationId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                placedAt:
                  type: string
                shipDate:
                  type:
                    - string
                    - 'null'
                expectedDeliveryDate:
                  type:
                    - string
                    - 'null'
                shippingCosts:
                  type: number
                  minimum: 0
                setupCosts:
                  type: number
                  minimum: 0
                otherCosts:
                  type: number
                  minimum: 0
                notes:
                  type:
                    - string
                    - 'null'
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      materialId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      skuId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: number
                        exclusiveMinimum: 0
                      unitCost:
                        type: number
                        minimum: 0
                    required:
                      - quantity
              required:
                - vendorId
                - targetType
                - status
                - items
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  purchaseOrder:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      poNumber:
                        type: string
                      vendorId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      targetType:
                        type: string
                        enum:
                          - materials
                          - finished_goods
                      status:
                        type: string
                        enum:
                          - Planning
                          - Placed
                          - In Transit
                          - Partial
                          - Received
                          - Paid
                          - Cancelled
                      shipToLocationId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      planningAt:
                        type:
                          - string
                          - 'null'
                      placedAt:
                        type: string
                      shipDate:
                        type:
                          - string
                          - 'null'
                      inTransitAt:
                        type:
                          - string
                          - 'null'
                      partialAt:
                        type:
                          - string
                          - 'null'
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      receivedAt:
                        type:
                          - string
                          - 'null'
                      paidAt:
                        type:
                          - string
                          - 'null'
                      cancelledAt:
                        type:
                          - string
                          - 'null'
                      shippingCosts:
                        anyOf:
                          - type: string
                          - type: number
                      setupCosts:
                        anyOf:
                          - type: string
                          - type: number
                      otherCosts:
                        anyOf:
                          - type: string
                          - type: number
                      notes:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - poNumber
                      - vendorId
                      - targetType
                      - status
                      - shipToLocationId
                      - planningAt
                      - placedAt
                      - shipDate
                      - inTransitAt
                      - partialAt
                      - expectedDeliveryDate
                      - receivedAt
                      - paidAt
                      - cancelledAt
                      - shippingCosts
                      - setupCosts
                      - otherCosts
                      - notes
                      - createdAt
                      - updatedAt
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        purchaseOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                      required:
                        - id
                        - orgId
                        - purchaseOrderId
                        - materialId
                        - skuId
                        - quantity
                        - unitCost
                required:
                  - purchaseOrder
                  - items
    get:
      tags:
        - PurchaseOrders
      summary: List POs
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        poNumber:
                          type: string
                        vendorId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        targetType:
                          type: string
                          enum:
                            - materials
                            - finished_goods
                        status:
                          type: string
                          enum:
                            - Planning
                            - Placed
                            - In Transit
                            - Partial
                            - Received
                            - Paid
                            - Cancelled
                        shipToLocationId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        planningAt:
                          type:
                            - string
                            - 'null'
                        placedAt:
                          type: string
                        shipDate:
                          type:
                            - string
                            - 'null'
                        inTransitAt:
                          type:
                            - string
                            - 'null'
                        partialAt:
                          type:
                            - string
                            - 'null'
                        expectedDeliveryDate:
                          type:
                            - string
                            - 'null'
                        receivedAt:
                          type:
                            - string
                            - 'null'
                        paidAt:
                          type:
                            - string
                            - 'null'
                        cancelledAt:
                          type:
                            - string
                            - 'null'
                        shippingCosts:
                          anyOf:
                            - type: string
                            - type: number
                        setupCosts:
                          anyOf:
                            - type: string
                            - type: number
                        otherCosts:
                          anyOf:
                            - type: string
                            - type: number
                        notes:
                          type:
                            - string
                            - 'null'
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - poNumber
                        - vendorId
                        - targetType
                        - status
                        - shipToLocationId
                        - planningAt
                        - placedAt
                        - shipDate
                        - inTransitAt
                        - partialAt
                        - expectedDeliveryDate
                        - receivedAt
                        - paidAt
                        - cancelledAt
                        - shippingCosts
                        - setupCosts
                        - otherCosts
                        - notes
                        - createdAt
                        - updatedAt
                required:
                  - data
  /purchase-orders/{id}:
    patch:
      tags:
        - PurchaseOrders
      summary: Update PO
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                vendorId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                targetType:
                  type: string
                  enum:
                    - materials
                    - finished_goods
                status:
                  type: string
                  enum:
                    - Planning
                    - Placed
                    - In Transit
                    - Partial
                    - Received
                    - Paid
                    - Cancelled
                shipToLocationId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                placedAt:
                  type: string
                shipDate:
                  type:
                    - string
                    - 'null'
                expectedDeliveryDate:
                  type:
                    - string
                    - 'null'
                shippingCosts:
                  type: number
                  minimum: 0
                setupCosts:
                  type: number
                  minimum: 0
                otherCosts:
                  type: number
                  minimum: 0
                notes:
                  type:
                    - string
                    - 'null'
                planningAt:
                  type:
                    - string
                    - 'null'
                inTransitAt:
                  type:
                    - string
                    - 'null'
                partialAt:
                  type:
                    - string
                    - 'null'
                receivedAt:
                  type:
                    - string
                    - 'null'
                paidAt:
                  type:
                    - string
                    - 'null'
                cancelledAt:
                  type:
                    - string
                    - 'null'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  poNumber:
                    type: string
                  vendorId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  targetType:
                    type: string
                    enum:
                      - materials
                      - finished_goods
                  status:
                    type: string
                    enum:
                      - Planning
                      - Placed
                      - In Transit
                      - Partial
                      - Received
                      - Paid
                      - Cancelled
                  shipToLocationId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  planningAt:
                    type:
                      - string
                      - 'null'
                  placedAt:
                    type: string
                  shipDate:
                    type:
                      - string
                      - 'null'
                  inTransitAt:
                    type:
                      - string
                      - 'null'
                  partialAt:
                    type:
                      - string
                      - 'null'
                  expectedDeliveryDate:
                    type:
                      - string
                      - 'null'
                  receivedAt:
                    type:
                      - string
                      - 'null'
                  paidAt:
                    type:
                      - string
                      - 'null'
                  cancelledAt:
                    type:
                      - string
                      - 'null'
                  shippingCosts:
                    anyOf:
                      - type: string
                      - type: number
                  setupCosts:
                    anyOf:
                      - type: string
                      - type: number
                  otherCosts:
                    anyOf:
                      - type: string
                      - type: number
                  notes:
                    type:
                      - string
                      - 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - poNumber
                  - vendorId
                  - targetType
                  - status
                  - shipToLocationId
                  - planningAt
                  - placedAt
                  - shipDate
                  - inTransitAt
                  - partialAt
                  - expectedDeliveryDate
                  - receivedAt
                  - paidAt
                  - cancelledAt
                  - shippingCosts
                  - setupCosts
                  - otherCosts
                  - notes
                  - createdAt
                  - updatedAt
    delete:
      tags:
        - PurchaseOrders
      summary: Delete PO
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
    get:
      tags:
        - PurchaseOrders
      summary: Get PO detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  purchaseOrder:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      poNumber:
                        type: string
                      vendorId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      targetType:
                        type: string
                        enum:
                          - materials
                          - finished_goods
                      status:
                        type: string
                        enum:
                          - Planning
                          - Placed
                          - In Transit
                          - Partial
                          - Received
                          - Paid
                          - Cancelled
                      shipToLocationId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      planningAt:
                        type:
                          - string
                          - 'null'
                      placedAt:
                        type: string
                      shipDate:
                        type:
                          - string
                          - 'null'
                      inTransitAt:
                        type:
                          - string
                          - 'null'
                      partialAt:
                        type:
                          - string
                          - 'null'
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      receivedAt:
                        type:
                          - string
                          - 'null'
                      paidAt:
                        type:
                          - string
                          - 'null'
                      cancelledAt:
                        type:
                          - string
                          - 'null'
                      shippingCosts:
                        anyOf:
                          - type: string
                          - type: number
                      setupCosts:
                        anyOf:
                          - type: string
                          - type: number
                      otherCosts:
                        anyOf:
                          - type: string
                          - type: number
                      notes:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - poNumber
                      - vendorId
                      - targetType
                      - status
                      - shipToLocationId
                      - planningAt
                      - placedAt
                      - shipDate
                      - inTransitAt
                      - partialAt
                      - expectedDeliveryDate
                      - receivedAt
                      - paidAt
                      - cancelledAt
                      - shippingCosts
                      - setupCosts
                      - otherCosts
                      - notes
                      - createdAt
                      - updatedAt
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        purchaseOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                      required:
                        - id
                        - orgId
                        - purchaseOrderId
                        - materialId
                        - skuId
                        - quantity
                        - unitCost
                required:
                  - purchaseOrder
                  - items
  /purchase-orders/bulk-import:
    post:
      tags:
        - PurchaseOrders
      summary: Bulk-import POs
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rows:
                  type: array
                  items:
                    type: object
                    properties:
                      vendorId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      targetType:
                        type: string
                        enum:
                          - materials
                          - finished_goods
                      status:
                        type: string
                        enum:
                          - Planning
                          - Placed
                          - In Transit
                          - Partial
                          - Received
                          - Paid
                          - Cancelled
                      shipToLocationId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      placedAt:
                        type: string
                      shipDate:
                        type:
                          - string
                          - 'null'
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      shippingCosts:
                        type: number
                        minimum: 0
                      setupCosts:
                        type: number
                        minimum: 0
                      otherCosts:
                        type: number
                        minimum: 0
                      notes:
                        type:
                          - string
                          - 'null'
                      items:
                        type: array
                        items:
                          type: object
                          properties:
                            materialId:
                              type:
                                - string
                                - 'null'
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            skuId:
                              type:
                                - string
                                - 'null'
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            quantity:
                              type: number
                              exclusiveMinimum: 0
                            unitCost:
                              type: number
                              minimum: 0
                          required:
                            - quantity
                    required:
                      - vendorId
                      - targetType
                      - status
                      - items
              required:
                - rows
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ids:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - ids
  /purchase-orders/{id}/items:
    post:
      tags:
        - PurchaseOrders
      summary: Add item to PO
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                materialId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                skuId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: number
                  exclusiveMinimum: 0
                unitCost:
                  type: number
                  minimum: 0
              required:
                - quantity
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  purchaseOrderId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  materialId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  skuId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  quantity:
                    anyOf:
                      - type: string
                      - type: number
                  unitCost:
                    anyOf:
                      - type: string
                      - type: number
                required:
                  - id
                  - orgId
                  - purchaseOrderId
                  - materialId
                  - skuId
                  - quantity
                  - unitCost
    get:
      tags:
        - PurchaseOrders
      summary: List PO items
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        purchaseOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                      required:
                        - id
                        - orgId
                        - purchaseOrderId
                        - materialId
                        - skuId
                        - quantity
                        - unitCost
                required:
                  - data
  /purchase-order-items/{id}:
    patch:
      tags:
        - PurchaseOrders
      summary: Update PO item
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                materialId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                skuId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: number
                  exclusiveMinimum: 0
                unitCost:
                  type: number
                  minimum: 0
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  purchaseOrderId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  materialId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  skuId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  quantity:
                    anyOf:
                      - type: string
                      - type: number
                  unitCost:
                    anyOf:
                      - type: string
                      - type: number
                required:
                  - id
                  - orgId
                  - purchaseOrderId
                  - materialId
                  - skuId
                  - quantity
                  - unitCost
    delete:
      tags:
        - PurchaseOrders
      summary: Remove PO item
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
  /purchase-orders/{id}/receipts:
    post:
      tags:
        - PurchaseOrders
      summary: Create receipt against PO
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                receiptDate:
                  type: string
                notes:
                  type:
                    - string
                    - 'null'
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      materialId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      skuId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: number
                        exclusiveMinimum: 0
                      unitCost:
                        type: number
                        minimum: 0
                    required:
                      - quantity
              required:
                - items
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  purchaseOrder:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      poNumber:
                        type: string
                      vendorId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      targetType:
                        type: string
                        enum:
                          - materials
                          - finished_goods
                      status:
                        type: string
                        enum:
                          - Planning
                          - Placed
                          - In Transit
                          - Partial
                          - Received
                          - Paid
                          - Cancelled
                      shipToLocationId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      planningAt:
                        type:
                          - string
                          - 'null'
                      placedAt:
                        type: string
                      shipDate:
                        type:
                          - string
                          - 'null'
                      inTransitAt:
                        type:
                          - string
                          - 'null'
                      partialAt:
                        type:
                          - string
                          - 'null'
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      receivedAt:
                        type:
                          - string
                          - 'null'
                      paidAt:
                        type:
                          - string
                          - 'null'
                      cancelledAt:
                        type:
                          - string
                          - 'null'
                      shippingCosts:
                        anyOf:
                          - type: string
                          - type: number
                      setupCosts:
                        anyOf:
                          - type: string
                          - type: number
                      otherCosts:
                        anyOf:
                          - type: string
                          - type: number
                      notes:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - poNumber
                      - vendorId
                      - targetType
                      - status
                      - shipToLocationId
                      - planningAt
                      - placedAt
                      - shipDate
                      - inTransitAt
                      - partialAt
                      - expectedDeliveryDate
                      - receivedAt
                      - paidAt
                      - cancelledAt
                      - shippingCosts
                      - setupCosts
                      - otherCosts
                      - notes
                      - createdAt
                      - updatedAt
                  receipt:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      purchaseOrderId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      receiptDate:
                        type: string
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - purchaseOrderId
                      - receiptDate
                      - createdAt
                      - updatedAt
                  receiptItems:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        receiptId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - receiptId
                        - materialId
                        - skuId
                        - quantity
                        - unitCost
                        - createdAt
                required:
                  - purchaseOrder
                  - receipt
                  - receiptItems
        '409':
          description: PO terminal
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    get:
      tags:
        - PurchaseOrders
      summary: List PO receipts
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        purchaseOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        receiptDate:
                          type: string
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - purchaseOrderId
                        - receiptDate
                        - createdAt
                        - updatedAt
                required:
                  - data
  /purchase-order-receipts/{id}:
    patch:
      tags:
        - PurchaseOrders
      summary: Update PO receipt
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                receiptDate:
                  type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  purchaseOrderId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  receiptDate:
                    type: string
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - purchaseOrderId
                  - receiptDate
                  - createdAt
                  - updatedAt
    delete:
      tags:
        - PurchaseOrders
      summary: Delete PO receipt
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
    get:
      tags:
        - PurchaseOrders
      summary: Get PO receipt detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  receipt:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      purchaseOrderId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      receiptDate:
                        type: string
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - purchaseOrderId
                      - receiptDate
                      - createdAt
                      - updatedAt
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        receiptId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - receiptId
                        - materialId
                        - skuId
                        - quantity
                        - unitCost
                        - createdAt
                required:
                  - receipt
                  - items
  /purchase-order-items:
    get:
      tags:
        - PurchaseOrders
      summary: List items across POs
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        purchaseOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                      required:
                        - id
                        - orgId
                        - purchaseOrderId
                        - materialId
                        - skuId
                        - quantity
                        - unitCost
                required:
                  - data
  /purchase-orders/{id}/pdf:
    get:
      tags:
        - PurchaseOrders
      summary: Generate PO PDF
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/pdf:
              schema:
                type: string
                format: binary
  /purchase-order-status-types:
    get:
      tags:
        - PurchaseOrders
      summary: List PO status enum values
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: string
                required:
                  - data
  /work-orders:
    post:
      tags:
        - WorkOrders
      summary: Create WO
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                  enum:
                    - Draft
                    - Entered
                    - Placed
                    - Production
                    - In Transit
                    - Partial
                    - Received
                    - Completed
                    - Cancelled
                workSiteLocationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                orderDate:
                  type: string
                expectedDeliveryDate:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      skuId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: integer
                        minimum: 1
                      conversionCost:
                        type: number
                        minimum: 0
                    required:
                      - skuId
                      - quantity
              required:
                - status
                - workSiteLocationId
                - items
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  workOrder:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      woNumber:
                        type: string
                      status:
                        type: string
                        enum:
                          - Draft
                          - Entered
                          - Placed
                          - Production
                          - In Transit
                          - Partial
                          - Received
                          - Completed
                          - Cancelled
                      workSiteId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      draftAt:
                        type:
                          - string
                          - 'null'
                      enteredAt:
                        type:
                          - string
                          - 'null'
                      placedAt:
                        type:
                          - string
                          - 'null'
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      productionStartedAt:
                        type:
                          - string
                          - 'null'
                      inTransitAt:
                        type:
                          - string
                          - 'null'
                      partialAt:
                        type:
                          - string
                          - 'null'
                      receivedAt:
                        type:
                          - string
                          - 'null'
                      completedAt:
                        type:
                          - string
                          - 'null'
                      cancelledAt:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - woNumber
                      - status
                      - workSiteId
                      - draftAt
                      - enteredAt
                      - placedAt
                      - expectedDeliveryDate
                      - productionStartedAt
                      - inTransitAt
                      - partialAt
                      - receivedAt
                      - completedAt
                      - cancelledAt
                      - notes
                      - createdAt
                      - updatedAt
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        workOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          type: integer
                        conversionCost:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - workOrderId
                        - skuId
                        - quantity
                        - conversionCost
                        - createdAt
                  inputs:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        workOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        workOrderItemId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        inputSkuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - workOrderId
                        - workOrderItemId
                        - materialId
                        - inputSkuId
                        - quantity
                        - createdAt
                required:
                  - workOrder
                  - items
                  - inputs
    get:
      tags:
        - WorkOrders
      summary: List WOs
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        woNumber:
                          type: string
                        status:
                          type: string
                          enum:
                            - Draft
                            - Entered
                            - Placed
                            - Production
                            - In Transit
                            - Partial
                            - Received
                            - Completed
                            - Cancelled
                        workSiteId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        draftAt:
                          type:
                            - string
                            - 'null'
                        enteredAt:
                          type:
                            - string
                            - 'null'
                        placedAt:
                          type:
                            - string
                            - 'null'
                        expectedDeliveryDate:
                          type:
                            - string
                            - 'null'
                        productionStartedAt:
                          type:
                            - string
                            - 'null'
                        inTransitAt:
                          type:
                            - string
                            - 'null'
                        partialAt:
                          type:
                            - string
                            - 'null'
                        receivedAt:
                          type:
                            - string
                            - 'null'
                        completedAt:
                          type:
                            - string
                            - 'null'
                        cancelledAt:
                          type:
                            - string
                            - 'null'
                        notes:
                          type:
                            - string
                            - 'null'
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - woNumber
                        - status
                        - workSiteId
                        - draftAt
                        - enteredAt
                        - placedAt
                        - expectedDeliveryDate
                        - productionStartedAt
                        - inTransitAt
                        - partialAt
                        - receivedAt
                        - completedAt
                        - cancelledAt
                        - notes
                        - createdAt
                        - updatedAt
                required:
                  - data
  /work-orders/{id}:
    patch:
      tags:
        - WorkOrders
      summary: Update WO
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                  enum:
                    - Draft
                    - Entered
                    - Placed
                    - Production
                    - In Transit
                    - Partial
                    - Received
                    - Completed
                    - Cancelled
                workSiteLocationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                orderDate:
                  type: string
                expectedDeliveryDate:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
                placedAt:
                  type: string
                draftAt:
                  type:
                    - string
                    - 'null'
                enteredAt:
                  type:
                    - string
                    - 'null'
                productionStartedAt:
                  type:
                    - string
                    - 'null'
                inTransitAt:
                  type:
                    - string
                    - 'null'
                partialAt:
                  type:
                    - string
                    - 'null'
                receivedAt:
                  type:
                    - string
                    - 'null'
                completedAt:
                  type:
                    - string
                    - 'null'
                cancelledAt:
                  type:
                    - string
                    - 'null'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  woNumber:
                    type: string
                  status:
                    type: string
                    enum:
                      - Draft
                      - Entered
                      - Placed
                      - Production
                      - In Transit
                      - Partial
                      - Received
                      - Completed
                      - Cancelled
                  workSiteId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  draftAt:
                    type:
                      - string
                      - 'null'
                  enteredAt:
                    type:
                      - string
                      - 'null'
                  placedAt:
                    type:
                      - string
                      - 'null'
                  expectedDeliveryDate:
                    type:
                      - string
                      - 'null'
                  productionStartedAt:
                    type:
                      - string
                      - 'null'
                  inTransitAt:
                    type:
                      - string
                      - 'null'
                  partialAt:
                    type:
                      - string
                      - 'null'
                  receivedAt:
                    type:
                      - string
                      - 'null'
                  completedAt:
                    type:
                      - string
                      - 'null'
                  cancelledAt:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - woNumber
                  - status
                  - workSiteId
                  - draftAt
                  - enteredAt
                  - placedAt
                  - expectedDeliveryDate
                  - productionStartedAt
                  - inTransitAt
                  - partialAt
                  - receivedAt
                  - completedAt
                  - cancelledAt
                  - notes
                  - createdAt
                  - updatedAt
    delete:
      tags:
        - WorkOrders
      summary: Delete WO
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
    get:
      tags:
        - WorkOrders
      summary: Get WO detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  workOrder:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      woNumber:
                        type: string
                      status:
                        type: string
                        enum:
                          - Draft
                          - Entered
                          - Placed
                          - Production
                          - In Transit
                          - Partial
                          - Received
                          - Completed
                          - Cancelled
                      workSiteId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      draftAt:
                        type:
                          - string
                          - 'null'
                      enteredAt:
                        type:
                          - string
                          - 'null'
                      placedAt:
                        type:
                          - string
                          - 'null'
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      productionStartedAt:
                        type:
                          - string
                          - 'null'
                      inTransitAt:
                        type:
                          - string
                          - 'null'
                      partialAt:
                        type:
                          - string
                          - 'null'
                      receivedAt:
                        type:
                          - string
                          - 'null'
                      completedAt:
                        type:
                          - string
                          - 'null'
                      cancelledAt:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - woNumber
                      - status
                      - workSiteId
                      - draftAt
                      - enteredAt
                      - placedAt
                      - expectedDeliveryDate
                      - productionStartedAt
                      - inTransitAt
                      - partialAt
                      - receivedAt
                      - completedAt
                      - cancelledAt
                      - notes
                      - createdAt
                      - updatedAt
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        workOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          type: integer
                        conversionCost:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - workOrderId
                        - skuId
                        - quantity
                        - conversionCost
                        - createdAt
                  inputs:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        workOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        workOrderItemId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        inputSkuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - workOrderId
                        - workOrderItemId
                        - materialId
                        - inputSkuId
                        - quantity
                        - createdAt
                required:
                  - workOrder
                  - items
                  - inputs
  /work-orders/bulk-import:
    post:
      tags:
        - WorkOrders
      summary: Bulk-import WOs
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rows:
                  type: array
                  items:
                    type: object
                    properties:
                      status:
                        type: string
                        enum:
                          - Draft
                          - Entered
                          - Placed
                          - Production
                          - In Transit
                          - Partial
                          - Received
                          - Completed
                          - Cancelled
                      workSiteLocationId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orderDate:
                        type: string
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      items:
                        type: array
                        items:
                          type: object
                          properties:
                            skuId:
                              type: string
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            quantity:
                              type: integer
                              minimum: 1
                            conversionCost:
                              type: number
                              minimum: 0
                          required:
                            - skuId
                            - quantity
                    required:
                      - status
                      - workSiteLocationId
                      - items
              required:
                - rows
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ids:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - ids
  /work-orders/{id}/items:
    post:
      tags:
        - WorkOrders
      summary: Add item to WO
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                skuId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: integer
                  minimum: 1
                conversionCost:
                  type: number
                  minimum: 0
              required:
                - skuId
                - quantity
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  item:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      workOrderId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      skuId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: integer
                      conversionCost:
                        anyOf:
                          - type: string
                          - type: number
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - workOrderId
                      - skuId
                      - quantity
                      - conversionCost
                      - createdAt
                  inputs:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        workOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        workOrderItemId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        inputSkuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - workOrderId
                        - workOrderItemId
                        - materialId
                        - inputSkuId
                        - quantity
                        - createdAt
                required:
                  - item
                  - inputs
        '409':
          description: Receipts exist / duplicate SKU
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /work-order-items/{id}:
    patch:
      tags:
        - WorkOrders
      summary: Update WO item
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                quantity:
                  type: integer
                  minimum: 1
                conversionCost:
                  type: number
                  minimum: 0
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  item:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      workOrderId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      skuId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: integer
                      conversionCost:
                        anyOf:
                          - type: string
                          - type: number
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - workOrderId
                      - skuId
                      - quantity
                      - conversionCost
                      - createdAt
                  inputs:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        workOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        workOrderItemId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        inputSkuId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - workOrderId
                        - workOrderItemId
                        - materialId
                        - inputSkuId
                        - quantity
                        - createdAt
                required:
                  - item
                  - inputs
        '409':
          description: Receipts exist
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    delete:
      tags:
        - WorkOrders
      summary: Remove WO item
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '409':
          description: Receipts exist
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /work-orders/{id}/receipts:
    post:
      tags:
        - WorkOrders
      summary: Create receipt against WO
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                receiptDate:
                  type: string
                notes:
                  type:
                    - string
                    - 'null'
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      skuId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: integer
                        minimum: 1
                      unitCost:
                        type: number
                        minimum: 0
                    required:
                      - skuId
                      - quantity
              required:
                - items
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  workOrder:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      woNumber:
                        type: string
                      status:
                        type: string
                        enum:
                          - Draft
                          - Entered
                          - Placed
                          - Production
                          - In Transit
                          - Partial
                          - Received
                          - Completed
                          - Cancelled
                      workSiteId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      draftAt:
                        type:
                          - string
                          - 'null'
                      enteredAt:
                        type:
                          - string
                          - 'null'
                      placedAt:
                        type:
                          - string
                          - 'null'
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      productionStartedAt:
                        type:
                          - string
                          - 'null'
                      inTransitAt:
                        type:
                          - string
                          - 'null'
                      partialAt:
                        type:
                          - string
                          - 'null'
                      receivedAt:
                        type:
                          - string
                          - 'null'
                      completedAt:
                        type:
                          - string
                          - 'null'
                      cancelledAt:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - woNumber
                      - status
                      - workSiteId
                      - draftAt
                      - enteredAt
                      - placedAt
                      - expectedDeliveryDate
                      - productionStartedAt
                      - inTransitAt
                      - partialAt
                      - receivedAt
                      - completedAt
                      - cancelledAt
                      - notes
                      - createdAt
                      - updatedAt
                  receipt:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      workOrderId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      receiptDate:
                        type: string
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - workOrderId
                      - receiptDate
                      - createdAt
                  receiptItems:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        receiptId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          type: integer
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - receiptId
                        - skuId
                        - quantity
                        - unitCost
                        - createdAt
                required:
                  - workOrder
                  - receipt
                  - receiptItems
        '409':
          description: WO terminal
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    get:
      tags:
        - WorkOrders
      summary: List WO receipts
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        workOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        receiptDate:
                          type: string
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - workOrderId
                        - receiptDate
                        - createdAt
                required:
                  - data
  /work-order-receipts/{id}:
    patch:
      tags:
        - WorkOrders
      summary: Update WO receipt
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                receiptDate:
                  type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  workOrderId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  receiptDate:
                    type: string
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - workOrderId
                  - receiptDate
                  - createdAt
    delete:
      tags:
        - WorkOrders
      summary: Delete WO receipt
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
    get:
      tags:
        - WorkOrders
      summary: Get WO receipt detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  receipt:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      workOrderId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      receiptDate:
                        type: string
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - workOrderId
                      - receiptDate
                      - createdAt
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        receiptId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          type: integer
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - receiptId
                        - skuId
                        - quantity
                        - unitCost
                        - createdAt
                required:
                  - receipt
                  - items
  /work-order-status-types:
    get:
      tags:
        - WorkOrders
      summary: List WO status enum values
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: string
                required:
                  - data
  /production-orders:
    post:
      tags:
        - ProductionOrders
      summary: Create production order
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                  enum:
                    - Draft
                    - Entered
                    - Placed
                    - Production
                    - In Transit
                    - Partial
                    - Received
                    - Completed
                    - Cancelled
                locationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                orderDate:
                  type: string
                expectedDeliveryDate:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      skuId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: integer
                        minimum: 1
                      productionCost:
                        type:
                          - number
                          - 'null'
                        minimum: 0
                    required:
                      - skuId
                      - quantity
              required:
                - status
                - locationId
                - items
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  productionOrder:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      prodNumber:
                        type: string
                      status:
                        type: string
                        enum:
                          - Draft
                          - Entered
                          - Placed
                          - Production
                          - In Transit
                          - Partial
                          - Received
                          - Completed
                          - Cancelled
                      locationId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      placedAt:
                        type:
                          - string
                          - 'null'
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      draftAt:
                        type:
                          - string
                          - 'null'
                      enteredAt:
                        type:
                          - string
                          - 'null'
                      productionStartedAt:
                        type:
                          - string
                          - 'null'
                      inTransitAt:
                        type:
                          - string
                          - 'null'
                      partialAt:
                        type:
                          - string
                          - 'null'
                      receivedAt:
                        type:
                          - string
                          - 'null'
                      completedAt:
                        type:
                          - string
                          - 'null'
                      cancelledAt:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - prodNumber
                      - status
                      - locationId
                      - placedAt
                      - expectedDeliveryDate
                      - draftAt
                      - enteredAt
                      - productionStartedAt
                      - inTransitAt
                      - partialAt
                      - receivedAt
                      - completedAt
                      - cancelledAt
                      - notes
                      - createdAt
                      - updatedAt
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        productionOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          type: integer
                        productionCost:
                          anyOf:
                            - type: string
                            - type: number
                            - type: 'null'
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - productionOrderId
                        - skuId
                        - quantity
                        - productionCost
                        - createdAt
                  inputs:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        productionOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        productionOrderItemId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - productionOrderId
                        - productionOrderItemId
                        - materialId
                        - quantity
                        - createdAt
                required:
                  - productionOrder
                  - items
                  - inputs
    get:
      tags:
        - ProductionOrders
      summary: List production orders
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        prodNumber:
                          type: string
                        status:
                          type: string
                          enum:
                            - Draft
                            - Entered
                            - Placed
                            - Production
                            - In Transit
                            - Partial
                            - Received
                            - Completed
                            - Cancelled
                        locationId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        placedAt:
                          type:
                            - string
                            - 'null'
                        expectedDeliveryDate:
                          type:
                            - string
                            - 'null'
                        draftAt:
                          type:
                            - string
                            - 'null'
                        enteredAt:
                          type:
                            - string
                            - 'null'
                        productionStartedAt:
                          type:
                            - string
                            - 'null'
                        inTransitAt:
                          type:
                            - string
                            - 'null'
                        partialAt:
                          type:
                            - string
                            - 'null'
                        receivedAt:
                          type:
                            - string
                            - 'null'
                        completedAt:
                          type:
                            - string
                            - 'null'
                        cancelledAt:
                          type:
                            - string
                            - 'null'
                        notes:
                          type:
                            - string
                            - 'null'
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - prodNumber
                        - status
                        - locationId
                        - placedAt
                        - expectedDeliveryDate
                        - draftAt
                        - enteredAt
                        - productionStartedAt
                        - inTransitAt
                        - partialAt
                        - receivedAt
                        - completedAt
                        - cancelledAt
                        - notes
                        - createdAt
                        - updatedAt
                required:
                  - data
  /production-orders/{id}:
    patch:
      tags:
        - ProductionOrders
      summary: Update production order
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                  enum:
                    - Draft
                    - Entered
                    - Placed
                    - Production
                    - In Transit
                    - Partial
                    - Received
                    - Completed
                    - Cancelled
                locationId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                orderDate:
                  type: string
                expectedDeliveryDate:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
                placedAt:
                  type: string
                draftAt:
                  type:
                    - string
                    - 'null'
                enteredAt:
                  type:
                    - string
                    - 'null'
                productionStartedAt:
                  type:
                    - string
                    - 'null'
                inTransitAt:
                  type:
                    - string
                    - 'null'
                partialAt:
                  type:
                    - string
                    - 'null'
                receivedAt:
                  type:
                    - string
                    - 'null'
                completedAt:
                  type:
                    - string
                    - 'null'
                cancelledAt:
                  type:
                    - string
                    - 'null'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  prodNumber:
                    type: string
                  status:
                    type: string
                    enum:
                      - Draft
                      - Entered
                      - Placed
                      - Production
                      - In Transit
                      - Partial
                      - Received
                      - Completed
                      - Cancelled
                  locationId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  placedAt:
                    type:
                      - string
                      - 'null'
                  expectedDeliveryDate:
                    type:
                      - string
                      - 'null'
                  draftAt:
                    type:
                      - string
                      - 'null'
                  enteredAt:
                    type:
                      - string
                      - 'null'
                  productionStartedAt:
                    type:
                      - string
                      - 'null'
                  inTransitAt:
                    type:
                      - string
                      - 'null'
                  partialAt:
                    type:
                      - string
                      - 'null'
                  receivedAt:
                    type:
                      - string
                      - 'null'
                  completedAt:
                    type:
                      - string
                      - 'null'
                  cancelledAt:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - prodNumber
                  - status
                  - locationId
                  - placedAt
                  - expectedDeliveryDate
                  - draftAt
                  - enteredAt
                  - productionStartedAt
                  - inTransitAt
                  - partialAt
                  - receivedAt
                  - completedAt
                  - cancelledAt
                  - notes
                  - createdAt
                  - updatedAt
    delete:
      tags:
        - ProductionOrders
      summary: Delete production order
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
    get:
      tags:
        - ProductionOrders
      summary: Get production order detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  productionOrder:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      prodNumber:
                        type: string
                      status:
                        type: string
                        enum:
                          - Draft
                          - Entered
                          - Placed
                          - Production
                          - In Transit
                          - Partial
                          - Received
                          - Completed
                          - Cancelled
                      locationId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      placedAt:
                        type:
                          - string
                          - 'null'
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      draftAt:
                        type:
                          - string
                          - 'null'
                      enteredAt:
                        type:
                          - string
                          - 'null'
                      productionStartedAt:
                        type:
                          - string
                          - 'null'
                      inTransitAt:
                        type:
                          - string
                          - 'null'
                      partialAt:
                        type:
                          - string
                          - 'null'
                      receivedAt:
                        type:
                          - string
                          - 'null'
                      completedAt:
                        type:
                          - string
                          - 'null'
                      cancelledAt:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - prodNumber
                      - status
                      - locationId
                      - placedAt
                      - expectedDeliveryDate
                      - draftAt
                      - enteredAt
                      - productionStartedAt
                      - inTransitAt
                      - partialAt
                      - receivedAt
                      - completedAt
                      - cancelledAt
                      - notes
                      - createdAt
                      - updatedAt
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        productionOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          type: integer
                        productionCost:
                          anyOf:
                            - type: string
                            - type: number
                            - type: 'null'
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - productionOrderId
                        - skuId
                        - quantity
                        - productionCost
                        - createdAt
                  inputs:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        productionOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        productionOrderItemId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - productionOrderId
                        - productionOrderItemId
                        - materialId
                        - quantity
                        - createdAt
                required:
                  - productionOrder
                  - items
                  - inputs
  /production-orders/bulk-import:
    post:
      tags:
        - ProductionOrders
      summary: Bulk-import production orders
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rows:
                  type: array
                  items:
                    type: object
                    properties:
                      status:
                        type: string
                        enum:
                          - Draft
                          - Entered
                          - Placed
                          - Production
                          - In Transit
                          - Partial
                          - Received
                          - Completed
                          - Cancelled
                      locationId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orderDate:
                        type: string
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      items:
                        type: array
                        items:
                          type: object
                          properties:
                            skuId:
                              type: string
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            quantity:
                              type: integer
                              minimum: 1
                            productionCost:
                              type:
                                - number
                                - 'null'
                              minimum: 0
                          required:
                            - skuId
                            - quantity
                    required:
                      - status
                      - locationId
                      - items
              required:
                - rows
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ids:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - ids
  /production-orders/{id}/items:
    post:
      tags:
        - ProductionOrders
      summary: Add item to production order
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                skuId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                quantity:
                  type: integer
                  minimum: 1
                productionCost:
                  type:
                    - number
                    - 'null'
                  minimum: 0
              required:
                - skuId
                - quantity
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  item:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      productionOrderId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      skuId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: integer
                      productionCost:
                        anyOf:
                          - type: string
                          - type: number
                          - type: 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - productionOrderId
                      - skuId
                      - quantity
                      - productionCost
                      - createdAt
                  inputs:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        productionOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        productionOrderItemId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - productionOrderId
                        - productionOrderItemId
                        - materialId
                        - quantity
                        - createdAt
                required:
                  - item
                  - inputs
        '409':
          description: Receipts exist / duplicate SKU
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /production-order-items/{id}:
    patch:
      tags:
        - ProductionOrders
      summary: Update production order item
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                quantity:
                  type: integer
                  minimum: 1
                productionCost:
                  type:
                    - number
                    - 'null'
                  minimum: 0
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  item:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      productionOrderId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      skuId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: integer
                      productionCost:
                        anyOf:
                          - type: string
                          - type: number
                          - type: 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - productionOrderId
                      - skuId
                      - quantity
                      - productionCost
                      - createdAt
                  inputs:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        productionOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        productionOrderItemId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        materialId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - productionOrderId
                        - productionOrderItemId
                        - materialId
                        - quantity
                        - createdAt
                required:
                  - item
                  - inputs
        '409':
          description: Receipts exist
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    delete:
      tags:
        - ProductionOrders
      summary: Remove production order item
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '409':
          description: Receipts exist
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /production-orders/{id}/receipts:
    post:
      tags:
        - ProductionOrders
      summary: Create receipt against production order
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                receiptDate:
                  type: string
                notes:
                  type:
                    - string
                    - 'null'
                items:
                  type: array
                  items:
                    type: object
                    properties:
                      skuId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      quantity:
                        type: integer
                        minimum: 1
                    required:
                      - skuId
                      - quantity
              required:
                - items
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  productionOrder:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      prodNumber:
                        type: string
                      status:
                        type: string
                        enum:
                          - Draft
                          - Entered
                          - Placed
                          - Production
                          - In Transit
                          - Partial
                          - Received
                          - Completed
                          - Cancelled
                      locationId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      placedAt:
                        type:
                          - string
                          - 'null'
                      expectedDeliveryDate:
                        type:
                          - string
                          - 'null'
                      draftAt:
                        type:
                          - string
                          - 'null'
                      enteredAt:
                        type:
                          - string
                          - 'null'
                      productionStartedAt:
                        type:
                          - string
                          - 'null'
                      inTransitAt:
                        type:
                          - string
                          - 'null'
                      partialAt:
                        type:
                          - string
                          - 'null'
                      receivedAt:
                        type:
                          - string
                          - 'null'
                      completedAt:
                        type:
                          - string
                          - 'null'
                      cancelledAt:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - prodNumber
                      - status
                      - locationId
                      - placedAt
                      - expectedDeliveryDate
                      - draftAt
                      - enteredAt
                      - productionStartedAt
                      - inTransitAt
                      - partialAt
                      - receivedAt
                      - completedAt
                      - cancelledAt
                      - notes
                      - createdAt
                      - updatedAt
                  receipt:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      productionOrderId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      receiptDate:
                        type: string
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - productionOrderId
                      - receiptDate
                      - createdAt
                  receiptItems:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        receiptId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          type: integer
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - receiptId
                        - skuId
                        - quantity
                        - unitCost
                        - createdAt
                required:
                  - productionOrder
                  - receipt
                  - receiptItems
        '409':
          description: Order terminal
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    get:
      tags:
        - ProductionOrders
      summary: List production order receipts
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        productionOrderId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        receiptDate:
                          type: string
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - productionOrderId
                        - receiptDate
                        - createdAt
                required:
                  - data
  /production-order-receipts/{id}:
    patch:
      tags:
        - ProductionOrders
      summary: Update production order receipt
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                receiptDate:
                  type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  productionOrderId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  receiptDate:
                    type: string
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - productionOrderId
                  - receiptDate
                  - createdAt
    delete:
      tags:
        - ProductionOrders
      summary: Delete production order receipt
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
    get:
      tags:
        - ProductionOrders
      summary: Get production order receipt detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  receipt:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      productionOrderId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      receiptDate:
                        type: string
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - orgId
                      - productionOrderId
                      - receiptDate
                      - createdAt
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        receiptId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        skuId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        quantity:
                          type: integer
                        unitCost:
                          anyOf:
                            - type: string
                            - type: number
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - receiptId
                        - skuId
                        - quantity
                        - unitCost
                        - createdAt
                required:
                  - receipt
                  - items
  /production-order-status-types:
    get:
      tags:
        - ProductionOrders
      summary: List production order status enum values
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: string
                required:
                  - data
  /documents:
    post:
      tags:
        - Documents
      summary: Upload document
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                entityType:
                  type: string
                  enum:
                    - sales_order
                    - purchase_order
                    - work_order
                entityId:
                  type: string
                  format: uuid
              required:
                - file
                - entityType
                - entityId
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  entityType:
                    type: string
                    enum:
                      - sales_order
                      - purchase_order
                      - work_order
                  entityId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  gcsPath:
                    type: string
                  mimeType:
                    type:
                      - string
                      - 'null'
                  sizeBytes:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - entityType
                  - entityId
                  - name
                  - gcsPath
                  - mimeType
                  - sizeBytes
                  - createdAt
        '422':
          description: Validation failed
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
    get:
      tags:
        - Documents
      summary: List documents for an entity
      parameters:
        - schema:
            type: string
            enum:
              - sales_order
              - purchase_order
              - work_order
          required: true
          name: entityType
          in: query
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: entityId
          in: query
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        entityType:
                          type: string
                          enum:
                            - sales_order
                            - purchase_order
                            - work_order
                        entityId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        name:
                          type: string
                        gcsPath:
                          type: string
                        mimeType:
                          type:
                            - string
                            - 'null'
                        sizeBytes:
                          anyOf:
                            - type: string
                            - type: number
                            - type: 'null'
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - entityType
                        - entityId
                        - name
                        - gcsPath
                        - mimeType
                        - sizeBytes
                        - createdAt
                required:
                  - data
  /documents/{id}:
    delete:
      tags:
        - Documents
      summary: Delete document
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
    get:
      tags:
        - Documents
      summary: Get document detail (signed download URL)
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  entityType:
                    type: string
                    enum:
                      - sales_order
                      - purchase_order
                      - work_order
                  entityId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  gcsPath:
                    type: string
                  mimeType:
                    type:
                      - string
                      - 'null'
                  sizeBytes:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  signedUrl:
                    type: string
                required:
                  - id
                  - orgId
                  - entityType
                  - entityId
                  - name
                  - gcsPath
                  - mimeType
                  - sizeBytes
                  - createdAt
                  - signedUrl
  /user:
    post:
      tags:
        - Platform
      summary: Create user
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                email:
                  type: string
                  format: email
                displayName:
                  type:
                    - string
                    - 'null'
              required:
                - email
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  firebaseUid:
                    type: string
                  email:
                    type: string
                  displayName:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  lastLoginAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                      - type: 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - firebaseUid
                  - email
                  - displayName
                  - isActive
                  - lastLoginAt
                  - createdAt
                  - updatedAt
    get:
      tags:
        - Platform
      summary: Get user
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  user:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      firebaseUid:
                        type: string
                      email:
                        type: string
                      displayName:
                        type:
                          - string
                          - 'null'
                      isActive:
                        type: boolean
                      lastLoginAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                          - type: 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - firebaseUid
                      - email
                      - displayName
                      - isActive
                      - lastLoginAt
                      - createdAt
                      - updatedAt
                  organizations:
                    type: array
                    items:
                      type: object
                      properties:
                        organization:
                          type: object
                          properties:
                            id:
                              type: string
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            name:
                              type: string
                            slug:
                              type: string
                            isActive:
                              type: boolean
                            createdAt:
                              anyOf:
                                - type: string
                                - type: string
                                  format: date-time
                            updatedAt:
                              anyOf:
                                - type: string
                                - type: string
                                  format: date-time
                          required:
                            - id
                            - name
                            - slug
                            - isActive
                            - createdAt
                            - updatedAt
                        role:
                          type: string
                          enum:
                            - owner
                            - admin
                            - member
                            - viewer
                        settings:
                          type:
                            - object
                            - 'null'
                          properties:
                            orgId:
                              type: string
                              pattern: >-
                                ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                            legalName:
                              type:
                                - string
                                - 'null'
                            address:
                              type:
                                - string
                                - 'null'
                            city:
                              type:
                                - string
                                - 'null'
                            state:
                              type:
                                - string
                                - 'null'
                            country:
                              type:
                                - string
                                - 'null'
                            zipCode:
                              type:
                                - string
                                - 'null'
                            logoUrl:
                              type:
                                - string
                                - 'null'
                            contactEmail:
                              type:
                                - string
                                - 'null'
                            contactPhone:
                              type:
                                - string
                                - 'null'
                            createdAt:
                              anyOf:
                                - type: string
                                - type: string
                                  format: date-time
                            updatedAt:
                              anyOf:
                                - type: string
                                - type: string
                                  format: date-time
                          required:
                            - orgId
                            - legalName
                            - address
                            - city
                            - state
                            - country
                            - zipCode
                            - logoUrl
                            - contactEmail
                            - contactPhone
                            - createdAt
                            - updatedAt
                      required:
                        - organization
                        - role
                        - settings
                required:
                  - user
                  - organizations
    patch:
      tags:
        - Platform
      summary: Update user
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                displayName:
                  type:
                    - string
                    - 'null'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  firebaseUid:
                    type: string
                  email:
                    type: string
                  displayName:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  lastLoginAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                      - type: 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - firebaseUid
                  - email
                  - displayName
                  - isActive
                  - lastLoginAt
                  - createdAt
                  - updatedAt
    delete:
      tags:
        - Platform
      summary: Delete user
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
  /user/api-tokens:
    post:
      tags:
        - Platform
      summary: Create API token (PAT)
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
                orgId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                expiresInDays:
                  type:
                    - integer
                    - 'null'
                  minimum: 1
                  maximum: 3650
              required:
                - name
                - orgId
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  token:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      userId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      name:
                        type: string
                      tokenPrefix:
                        type: string
                      lastUsedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                          - type: 'null'
                      expiresAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                          - type: 'null'
                      revokedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                          - type: 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - userId
                      - orgId
                      - name
                      - tokenPrefix
                      - lastUsedAt
                      - expiresAt
                      - revokedAt
                      - createdAt
                  plaintext:
                    type: string
                required:
                  - token
                  - plaintext
    get:
      tags:
        - Platform
      summary: List my API tokens
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        userId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        name:
                          type: string
                        tokenPrefix:
                          type: string
                        lastUsedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                            - type: 'null'
                        expiresAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                            - type: 'null'
                        revokedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                            - type: 'null'
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - userId
                        - orgId
                        - name
                        - tokenPrefix
                        - lastUsedAt
                        - expiresAt
                        - revokedAt
                        - createdAt
                required:
                  - data
  /user/api-tokens/{id}:
    delete:
      tags:
        - Platform
      summary: Revoke API token
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Revoked
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
  /invitations:
    get:
      tags:
        - Platform
      summary: List my pending invitations
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        invitedBy:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        email:
                          type: string
                        role:
                          type: string
                          enum:
                            - owner
                            - admin
                            - member
                            - viewer
                        token:
                          type: string
                        expiresAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        acceptedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                            - type: 'null'
                        revokedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                            - type: 'null'
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - invitedBy
                        - email
                        - role
                        - token
                        - expiresAt
                        - acceptedAt
                        - revokedAt
                        - createdAt
                required:
                  - data
  /invitations/by-token/{token}:
    get:
      tags:
        - Platform
      summary: Look up invitation by token (public)
      parameters:
        - schema:
            type: string
          required: true
          name: token
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  invitation:
                    type: object
                    properties:
                      email:
                        type: string
                      role:
                        type: string
                        enum:
                          - owner
                          - admin
                          - member
                          - viewer
                      orgName:
                        type: string
                      expiresAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      status:
                        type: string
                        enum:
                          - pending
                          - accepted
                          - revoked
                          - expired
                    required:
                      - email
                      - role
                      - orgName
                      - expiresAt
                      - status
                required:
                  - invitation
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /invitations/accept:
    post:
      tags:
        - Platform
      summary: Accept invitation
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                token:
                  type: string
                displayName:
                  type:
                    - string
                    - 'null'
              required:
                - token
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  userId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  role:
                    type: string
                    enum:
                      - owner
                      - admin
                      - member
                      - viewer
                  isActive:
                    type: boolean
                  joinedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  lastActiveAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                      - type: 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - userId
                  - orgId
                  - role
                  - isActive
                  - joinedAt
                  - lastActiveAt
                  - createdAt
                  - updatedAt
        '409':
          description: Invalid transition
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /invitations/decline:
    post:
      tags:
        - Platform
      summary: Decline invitation
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                invitationId:
                  type: string
              required:
                - invitationId
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ok:
                    type: boolean
  /organizations:
    post:
      tags:
        - Platform
      summary: Create organization
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
                slug:
                  type: string
                  pattern: ^[a-z0-9][a-z0-9-]*[a-z0-9]$
              required:
                - name
                - slug
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  organization:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      name:
                        type: string
                      slug:
                        type: string
                      isActive:
                        type: boolean
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - name
                      - slug
                      - isActive
                      - createdAt
                      - updatedAt
                  membership:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      userId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      role:
                        type: string
                        enum:
                          - owner
                          - admin
                          - member
                          - viewer
                      isActive:
                        type: boolean
                      joinedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      lastActiveAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                          - type: 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - userId
                      - orgId
                      - role
                      - isActive
                      - joinedAt
                      - lastActiveAt
                      - createdAt
                      - updatedAt
                required:
                  - organization
                  - membership
  /organizations/current:
    get:
      tags:
        - Platform
      summary: Get current organization
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  organization:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      name:
                        type: string
                      slug:
                        type: string
                      isActive:
                        type: boolean
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - name
                      - slug
                      - isActive
                      - createdAt
                      - updatedAt
                  settings:
                    type:
                      - object
                      - 'null'
                    properties:
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      legalName:
                        type:
                          - string
                          - 'null'
                      address:
                        type:
                          - string
                          - 'null'
                      city:
                        type:
                          - string
                          - 'null'
                      state:
                        type:
                          - string
                          - 'null'
                      country:
                        type:
                          - string
                          - 'null'
                      zipCode:
                        type:
                          - string
                          - 'null'
                      logoUrl:
                        type:
                          - string
                          - 'null'
                      contactEmail:
                        type:
                          - string
                          - 'null'
                      contactPhone:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - orgId
                      - legalName
                      - address
                      - city
                      - state
                      - country
                      - zipCode
                      - logoUrl
                      - contactEmail
                      - contactPhone
                      - createdAt
                      - updatedAt
                required:
                  - organization
                  - settings
    patch:
      tags:
        - Platform
      summary: Update current organization
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                slug:
                  type: string
                legalName:
                  type:
                    - string
                    - 'null'
                address:
                  type:
                    - string
                    - 'null'
                city:
                  type:
                    - string
                    - 'null'
                state:
                  type:
                    - string
                    - 'null'
                country:
                  type:
                    - string
                    - 'null'
                zipCode:
                  type:
                    - string
                    - 'null'
                logoUrl:
                  type:
                    - string
                    - 'null'
                contactEmail:
                  type:
                    - string
                    - 'null'
                contactPhone:
                  type:
                    - string
                    - 'null'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  organization:
                    type: object
                    properties:
                      id:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      name:
                        type: string
                      slug:
                        type: string
                      isActive:
                        type: boolean
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - id
                      - name
                      - slug
                      - isActive
                      - createdAt
                      - updatedAt
                  settings:
                    type:
                      - object
                      - 'null'
                    properties:
                      orgId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      legalName:
                        type:
                          - string
                          - 'null'
                      address:
                        type:
                          - string
                          - 'null'
                      city:
                        type:
                          - string
                          - 'null'
                      state:
                        type:
                          - string
                          - 'null'
                      country:
                        type:
                          - string
                          - 'null'
                      zipCode:
                        type:
                          - string
                          - 'null'
                      logoUrl:
                        type:
                          - string
                          - 'null'
                      contactEmail:
                        type:
                          - string
                          - 'null'
                      contactPhone:
                        type:
                          - string
                          - 'null'
                      createdAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                      updatedAt:
                        anyOf:
                          - type: string
                          - type: string
                            format: date-time
                    required:
                      - orgId
                      - legalName
                      - address
                      - city
                      - state
                      - country
                      - zipCode
                      - logoUrl
                      - contactEmail
                      - contactPhone
                      - createdAt
                      - updatedAt
                required:
                  - organization
                  - settings
    delete:
      tags:
        - Platform
      summary: Delete current organization (purge)
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
  /organizations/current/members:
    get:
      tags:
        - Platform
      summary: List organization members
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        userId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        email:
                          type: string
                        displayName:
                          type:
                            - string
                            - 'null'
                        role:
                          type: string
                          enum:
                            - owner
                            - admin
                            - member
                            - viewer
                        isActive:
                          type: boolean
                        joinedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        lastActiveAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                            - type: 'null'
                      required:
                        - userId
                        - email
                        - displayName
                        - role
                        - isActive
                        - joinedAt
                        - lastActiveAt
                required:
                  - data
  /organizations/current/members/{userId}:
    patch:
      tags:
        - Platform
      summary: Update user role
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: userId
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                role:
                  type: string
                  enum:
                    - owner
                    - admin
                    - member
                    - viewer
              required:
                - role
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  userId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  role:
                    type: string
                    enum:
                      - owner
                      - admin
                      - member
                      - viewer
                  isActive:
                    type: boolean
                  joinedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  lastActiveAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                      - type: 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - userId
                  - orgId
                  - role
                  - isActive
                  - joinedAt
                  - lastActiveAt
                  - createdAt
                  - updatedAt
    delete:
      tags:
        - Platform
      summary: Remove user from org
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: userId
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
  /organizations/current/members/me:
    delete:
      tags:
        - Platform
      summary: Leave organization
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedOrg:
                    type: boolean
  /organizations/current/invitations:
    post:
      tags:
        - Platform
      summary: Send invitation
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                email:
                  type: string
                  format: email
                role:
                  type: string
                  enum:
                    - owner
                    - admin
                    - member
                    - viewer
                inviterDisplayName:
                  type: string
              required:
                - email
                - role
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  invitedBy:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  email:
                    type: string
                  role:
                    type: string
                    enum:
                      - owner
                      - admin
                      - member
                      - viewer
                  token:
                    type: string
                  expiresAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  acceptedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                      - type: 'null'
                  revokedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                      - type: 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - invitedBy
                  - email
                  - role
                  - token
                  - expiresAt
                  - acceptedAt
                  - revokedAt
                  - createdAt
    get:
      tags:
        - Platform
      summary: List organization invitations
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        invitedBy:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        email:
                          type: string
                        role:
                          type: string
                          enum:
                            - owner
                            - admin
                            - member
                            - viewer
                        token:
                          type: string
                        expiresAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        acceptedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                            - type: 'null'
                        revokedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                            - type: 'null'
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - invitedBy
                        - email
                        - role
                        - token
                        - expiresAt
                        - acceptedAt
                        - revokedAt
                        - createdAt
                required:
                  - data
  /organizations/current/invitations/{id}/resend:
    post:
      tags:
        - Platform
      summary: Resend invitation
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                inviterDisplayName:
                  type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  invitedBy:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  email:
                    type: string
                  role:
                    type: string
                    enum:
                      - owner
                      - admin
                      - member
                      - viewer
                  token:
                    type: string
                  expiresAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  acceptedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                      - type: 'null'
                  revokedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                      - type: 'null'
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - invitedBy
                  - email
                  - role
                  - token
                  - expiresAt
                  - acceptedAt
                  - revokedAt
                  - createdAt
  /organizations/current/invitations/{id}:
    delete:
      tags:
        - Platform
      summary: Revoke invitation
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Revoked
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
  /customers:
    post:
      tags:
        - Customers
      summary: Create customer
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
                typeId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                segmentId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                brokerId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                brokerFeePercent:
                  type:
                    - number
                    - 'null'
                address:
                  type:
                    - string
                    - 'null'
                city:
                  type:
                    - string
                    - 'null'
                state:
                  type:
                    - string
                    - 'null'
                country:
                  type:
                    - string
                    - 'null'
                  minLength: 2
                  maxLength: 2
                zipCode:
                  type:
                    - string
                    - 'null'
                parentId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                qboId:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
              required:
                - name
                - typeId
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  customerTypeId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  customerSegmentId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  brokerId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  brokerFeePercent:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  address:
                    type:
                      - string
                      - 'null'
                  city:
                    type:
                      - string
                      - 'null'
                  state:
                    type:
                      - string
                      - 'null'
                  country:
                    type:
                      - string
                      - 'null'
                  zipCode:
                    type:
                      - string
                      - 'null'
                  parentCustomerId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  qboId:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - customerTypeId
                  - customerSegmentId
                  - brokerId
                  - brokerFeePercent
                  - address
                  - city
                  - state
                  - country
                  - zipCode
                  - parentCustomerId
                  - qboId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
    get:
      tags:
        - Customers
      summary: List customers
      parameters:
        - schema:
            type: string
            enum:
              - 'true'
              - 'false'
          required: false
          name: active
          in: query
        - schema:
            type: string
          required: false
          name: type
          in: query
        - schema:
            type: string
          required: false
          name: segment
          in: query
        - schema:
            type: string
          required: false
          name: broker
          in: query
        - schema:
            type: string
          required: false
          name: parentCustomer
          in: query
        - schema:
            type: string
          required: false
          name: q
          in: query
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        name:
                          type: string
                        customerTypeId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        customerSegmentId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        brokerId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        brokerFeePercent:
                          anyOf:
                            - type: string
                            - type: number
                            - type: 'null'
                        address:
                          type:
                            - string
                            - 'null'
                        city:
                          type:
                            - string
                            - 'null'
                        state:
                          type:
                            - string
                            - 'null'
                        country:
                          type:
                            - string
                            - 'null'
                        zipCode:
                          type:
                            - string
                            - 'null'
                        parentCustomerId:
                          type:
                            - string
                            - 'null'
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        qboId:
                          type:
                            - string
                            - 'null'
                        notes:
                          type:
                            - string
                            - 'null'
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                        updatedAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - name
                        - customerTypeId
                        - customerSegmentId
                        - brokerId
                        - brokerFeePercent
                        - address
                        - city
                        - state
                        - country
                        - zipCode
                        - parentCustomerId
                        - qboId
                        - notes
                        - isActive
                        - createdAt
                        - updatedAt
                required:
                  - data
  /customers/{id}:
    patch:
      tags:
        - Customers
      summary: Update customer
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 255
                typeId:
                  type: string
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                segmentId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                brokerId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                brokerFeePercent:
                  type:
                    - number
                    - 'null'
                address:
                  type:
                    - string
                    - 'null'
                city:
                  type:
                    - string
                    - 'null'
                state:
                  type:
                    - string
                    - 'null'
                country:
                  type:
                    - string
                    - 'null'
                  minLength: 2
                  maxLength: 2
                zipCode:
                  type:
                    - string
                    - 'null'
                parentId:
                  type:
                    - string
                    - 'null'
                  pattern: >-
                    ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                qboId:
                  type:
                    - string
                    - 'null'
                notes:
                  type:
                    - string
                    - 'null'
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  customerTypeId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  customerSegmentId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  brokerId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  brokerFeePercent:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  address:
                    type:
                      - string
                      - 'null'
                  city:
                    type:
                      - string
                      - 'null'
                  state:
                    type:
                      - string
                      - 'null'
                  country:
                    type:
                      - string
                      - 'null'
                  zipCode:
                    type:
                      - string
                      - 'null'
                  parentCustomerId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  qboId:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - customerTypeId
                  - customerSegmentId
                  - brokerId
                  - brokerFeePercent
                  - address
                  - city
                  - state
                  - country
                  - zipCode
                  - parentCustomerId
                  - qboId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
    delete:
      tags:
        - Customers
      summary: Delete customer
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
    get:
      tags:
        - Customers
      summary: Get customer detail
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  customerTypeId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  customerSegmentId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  brokerId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  brokerFeePercent:
                    anyOf:
                      - type: string
                      - type: number
                      - type: 'null'
                  address:
                    type:
                      - string
                      - 'null'
                  city:
                    type:
                      - string
                      - 'null'
                  state:
                    type:
                      - string
                      - 'null'
                  country:
                    type:
                      - string
                      - 'null'
                  zipCode:
                    type:
                      - string
                      - 'null'
                  parentCustomerId:
                    type:
                      - string
                      - 'null'
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  qboId:
                    type:
                      - string
                      - 'null'
                  notes:
                    type:
                      - string
                      - 'null'
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                  updatedAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - customerTypeId
                  - customerSegmentId
                  - brokerId
                  - brokerFeePercent
                  - address
                  - city
                  - state
                  - country
                  - zipCode
                  - parentCustomerId
                  - qboId
                  - notes
                  - isActive
                  - createdAt
                  - updatedAt
  /customers/bulk-import:
    post:
      tags:
        - Customers
      summary: Bulk-import customers
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                rows:
                  type: array
                  items:
                    type: object
                    properties:
                      name:
                        type: string
                        minLength: 1
                        maxLength: 255
                      typeId:
                        type: string
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      segmentId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      brokerId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      brokerFeePercent:
                        type:
                          - number
                          - 'null'
                      address:
                        type:
                          - string
                          - 'null'
                      city:
                        type:
                          - string
                          - 'null'
                      state:
                        type:
                          - string
                          - 'null'
                      country:
                        type:
                          - string
                          - 'null'
                        minLength: 2
                        maxLength: 2
                      zipCode:
                        type:
                          - string
                          - 'null'
                      parentId:
                        type:
                          - string
                          - 'null'
                        pattern: >-
                          ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                      qboId:
                        type:
                          - string
                          - 'null'
                      notes:
                        type:
                          - string
                          - 'null'
                    required:
                      - name
                      - typeId
              required:
                - rows
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  ids:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - ids
  /customer-types:
    post:
      tags:
        - Customers
      summary: Create customer type
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
              required:
                - name
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    get:
      tags:
        - Customers
      summary: List customer types
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        name:
                          type: string
                        sortOrder:
                          type: integer
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - name
                        - sortOrder
                        - isActive
                        - createdAt
                required:
                  - data
  /customer-types/{id}:
    patch:
      tags:
        - Customers
      summary: Update customer type
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                sortOrder:
                  type: integer
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    delete:
      tags:
        - Customers
      summary: Delete customer type
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
        '409':
          description: In use
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                        enum:
                          - not_found
                          - in_use
                          - invalid_transition
                          - validation_failed
                          - forbidden
                          - unauthorized
                          - conflict
                          - internal_error
                      message:
                        type: string
                      details: {}
                    required:
                      - code
                      - message
                required:
                  - error
  /customer-segments:
    post:
      tags:
        - Customers
      summary: Create customer segment
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
              required:
                - name
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    get:
      tags:
        - Customers
      summary: List customer segments
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        name:
                          type: string
                        sortOrder:
                          type: integer
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - name
                        - sortOrder
                        - isActive
                        - createdAt
                required:
                  - data
  /customer-segments/{id}:
    patch:
      tags:
        - Customers
      summary: Update customer segment
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                sortOrder:
                  type: integer
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    delete:
      tags:
        - Customers
      summary: Delete customer segment
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
  /brokers:
    post:
      tags:
        - Customers
      summary: Create broker
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
              required:
                - name
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    get:
      tags:
        - Customers
      summary: List brokers
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        orgId:
                          type: string
                          pattern: >-
                            ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                        name:
                          type: string
                        sortOrder:
                          type: integer
                        isActive:
                          type: boolean
                        createdAt:
                          anyOf:
                            - type: string
                            - type: string
                              format: date-time
                      required:
                        - id
                        - orgId
                        - name
                        - sortOrder
                        - isActive
                        - createdAt
                required:
                  - data
  /brokers/{id}:
    patch:
      tags:
        - Customers
      summary: Update broker
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  minLength: 1
                  maxLength: 100
                sortOrder:
                  type: integer
                isActive:
                  type: boolean
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  orgId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                  name:
                    type: string
                  sortOrder:
                    type: integer
                  isActive:
                    type: boolean
                  createdAt:
                    anyOf:
                      - type: string
                      - type: string
                        format: date-time
                required:
                  - id
                  - orgId
                  - name
                  - sortOrder
                  - isActive
                  - createdAt
    delete:
      tags:
        - Customers
      summary: Delete broker
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: Deleted
          content:
            application/json:
              schema:
                type: object
                properties:
                  deletedId:
                    type: string
                    pattern: >-
                      ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - deletedId
  /customer-types/{id}/in-use:
    get:
      tags:
        - Customers
      summary: Check customer type usage
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  inUse:
                    type: boolean
                  customerCount:
                    type: integer
                  sampleCustomerIds:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - inUse
                  - customerCount
                  - sampleCustomerIds
  /customer-segments/{id}/in-use:
    get:
      tags:
        - Customers
      summary: Check customer segment usage
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  inUse:
                    type: boolean
                  customerCount:
                    type: integer
                  sampleCustomerIds:
                    type: array
                    items:
                      type: string
                      pattern: >-
                        ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
                required:
                  - inUse
                  - customerCount
                  - sampleCustomerIds
  /brokers/{id}/in-use:
    get:
      tags:
        - Customers
      summary: Check broker usage
      parameters:
        - schema:
            type: string
            pattern: >-
              ^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$
          required: true
          name: id
          in: path
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  inUse:
                    type: boolean
                  customerCount:
                    type: integer
                  soCount:
                    type: integer
                required:
                  - inUse
                  - customerCount
                  - soCount
webhooks: {}
