openapi: 3.0.4
info:
  title: Evolution Foundation - CRM Service - Pipeline Items
  description: Management of contacts, conversations, inboxes, labels and macros
  version: 1.1.0
servers:
- url: https://api.evoai.app
  description: Production server
- url: http://localhost:3000
  description: Development server
  variables:
    port:
      default: '3000'
- url: '{customUrl}'
  description: Custom server
  variables:
    customUrl:
      default: https://your-instance.com
      description: Enter your server URL
paths:
  /api/v1/pipelines/{pipeline_id}/pipeline_items:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: stage_id
      in: query
      required: false
      schema:
        type: string
        format: uuid
      description: Filter by stage
    - name: search
      in: query
      required: false
      schema:
        type: string
      description: Search by contact name, email, or conversation ID
    - name: sort_by
      in: query
      required: false
      schema:
        type: string
        enum:
        - created_at
        - updated_at
        - stage_name
        - contact_name
        default: created_at
    - name: sort_order
      in: query
      required: false
      schema:
        type: string
        enum:
        - asc
        - desc
        default: desc
    get:
      operationId: list-pipeline-items
      summary: List all items in a pipeline
      description: Get all items (deals/leads) in a pipeline with filtering and sorting
      security:
      - userApiKey: []
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/pipeline_item'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline items retrieved successfully
              examples:
                success:
                  value:
                    success: true
                    data: []
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Pipeline items retrieved successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid pipeline ID format
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items
                  method: GET
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid or missing authentication token
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items
                  method: GET
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: You do not have permission to access this pipeline
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items
                  method: GET
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items
                  method: GET
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INTERNAL_SERVER_ERROR
                  message: An unexpected error occurred
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items
                  method: GET
    post:
      operationId: create-pipeline-item
      summary: Add an item to pipeline
      description: Add a conversation or contact to the pipeline
      security:
      - userApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - type
              - item_id
              properties:
                type:
                  type: string
                  enum:
                  - conversation
                  - contact
                  description: Type of item to add
                item_id:
                  type: string
                  description: UUID of conversation or contact
                pipeline_stage_id:
                  type: string
                  format: uuid
                  description: Stage ID (if not provided, uses first stage)
                custom_fields:
                  type: object
                  description: Custom field values
      responses:
        '200':
          description: Item added successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: '#/components/schemas/pipeline_item'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline item added successfully
              examples:
                success:
                  value:
                    success: true
                    data:
                      id: 990e8400-e29b-41d4-a716-446655440004
                      pipeline_id: 550e8400-e29b-41d4-a716-446655440000
                      pipeline_stage_id: 770e8400-e29b-41d4-a716-446655440002
                      item_type: conversation
                      item_id: 880e8400-e29b-41d4-a716-446655440003
                      custom_fields: {}
                      created_at: '2024-01-15T10:30:00Z'
                      updated_at: '2024-01-15T10:30:00Z'
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Pipeline item added successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Item already in pipeline
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items
                  method: POST
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid or missing authentication token
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items
                  method: POST
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: You do not have permission to add items to this pipeline
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items
                  method: POST
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Conversation or contact not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items
                  method: POST
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Validation failed
                  details:
                    type:
                    - is required
                    item_id:
                    - is required
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items
                  method: POST
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INTERNAL_SERVER_ERROR
                  message: An unexpected error occurred
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items
                  method: POST
  /api/v1/pipelines/{pipeline_id}/pipeline_items/available_contacts:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: search
      in: query
      required: false
      schema:
        type: string
    get:
      operationId: get-available-contacts
      summary: Get available contacts
      description: Get contacts that can be added to this pipeline as leads
      security:
      - userApiKey: []
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/contact'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Available contacts retrieved successfully
              examples:
                success:
                  value:
                    success: true
                    data: []
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Available contacts retrieved successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid pipeline ID format
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/available_contacts
                  method: GET
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid or missing authentication token
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/available_contacts
                  method: GET
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: You do not have permission to access this pipeline
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/available_contacts
                  method: GET
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/available_contacts
                  method: GET
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INTERNAL_SERVER_ERROR
                  message: An unexpected error occurred
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/available_contacts
                  method: GET
  /api/v1/pipelines/{pipeline_id}/pipeline_items/available_conversations:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: search
      in: query
      required: false
      schema:
        type: string
    get:
      operationId: get-available-conversations
      summary: Get available conversations
      description: Get conversations that can be added to this pipeline (not already in it)
      security:
      - userApiKey: []
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/conversation'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Available conversations retrieved successfully
              examples:
                success:
                  value:
                    success: true
                    data: []
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Available conversations retrieved successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid pipeline ID format
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/available_conversations
                  method: GET
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid or missing authentication token
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/available_conversations
                  method: GET
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: You do not have permission to access this pipeline
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/available_conversations
                  method: GET
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/available_conversations
                  method: GET
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INTERNAL_SERVER_ERROR
                  message: An unexpected error occurred
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/available_conversations
                  method: GET
  /api/v1/pipelines/{pipeline_id}/pipeline_items/bulk_move:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    patch:
      operationId: bulk-move-items
      summary: Bulk move items to a stage
      description: Move multiple items to a new stage at once
      security:
      - userApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - conversation_ids
              - new_stage_id
              properties:
                conversation_ids:
                  type: array
                  items:
                    type: string
                  description: Array of item IDs to move
                new_stage_id:
                  type: string
                  format: uuid
                notes:
                  type: string
                  description: Optional notes for the movement
      responses:
        '200':
          description: Items moved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      moved_count:
                        type: integer
                        description: Number of items moved
                        example: 5
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Items moved successfully
              examples:
                success:
                  value:
                    success: true
                    data:
                      moved_count: 5
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Items moved successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid stage ID format
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/bulk_move
                  method: PATCH
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid or missing authentication token
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/bulk_move
                  method: PATCH
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: You do not have permission to move items in this pipeline
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/bulk_move
                  method: PATCH
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline or stage not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/bulk_move
                  method: PATCH
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Validation failed
                  details:
                    conversation_ids:
                    - is required
                    new_stage_id:
                    - is required
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/bulk_move
                  method: PATCH
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INTERNAL_SERVER_ERROR
                  message: An unexpected error occurred
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/bulk_move
                  method: PATCH
  /api/v1/pipelines/{pipeline_id}/pipeline_items/stats:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    get:
      operationId: get-pipeline-items-stats
      summary: Get items statistics
      description: Get statistics about pipeline items including services values and currency breakdown
      security:
      - userApiKey: []
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      total_conversations:
                        type: integer
                        example: 50
                      conversations_with_services:
                        type: integer
                        example: 30
                      total_services_value:
                        type: number
                        example: 15000.5
                      currency_breakdown:
                        type: object
                        additionalProperties:
                          type: number
                        example:
                          USD: 10000.0
                          BRL: 5000.5
                      average_services_per_conversation:
                        type: number
                        example: 500.02
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline items statistics retrieved successfully
              examples:
                success:
                  value:
                    success: true
                    data:
                      total_conversations: 50
                      conversations_with_services: 30
                      total_services_value: 15000.5
                      currency_breakdown:
                        USD: 10000.0
                        BRL: 5000.5
                      average_services_per_conversation: 500.02
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Pipeline items statistics retrieved successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid pipeline ID format
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/stats
                  method: GET
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid or missing authentication token
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/stats
                  method: GET
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: You do not have permission to access this pipeline
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/stats
                  method: GET
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/stats
                  method: GET
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INTERNAL_SERVER_ERROR
                  message: An unexpected error occurred
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/stats
                  method: GET
  /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      required: true
      schema:
        type: string
      description: Pipeline item ID, conversation ID, or conversation display_id
    patch:
      operationId: update-pipeline-item
      summary: Update a pipeline item
      security:
      - userApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - pipeline_item
              properties:
                pipeline_item:
                  type: object
                  properties:
                    custom_fields:
                      type: object
      responses:
        '200':
          description: Item updated successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: '#/components/schemas/pipeline_item'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline item updated successfully
              examples:
                success:
                  value:
                    success: true
                    data:
                      id: 990e8400-e29b-41d4-a716-446655440004
                      pipeline_id: 550e8400-e29b-41d4-a716-446655440000
                      pipeline_stage_id: 770e8400-e29b-41d4-a716-446655440002
                      item_type: conversation
                      item_id: 880e8400-e29b-41d4-a716-446655440003
                      custom_fields: {}
                      created_at: '2024-01-15T10:30:00Z'
                      updated_at: '2024-01-15T10:35:00Z'
                    meta:
                      timestamp: '2024-01-15T10:35:00Z'
                    message: Pipeline item updated successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid request data
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}
                  method: PATCH
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid or missing authentication token
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}
                  method: PATCH
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: You do not have permission to update this pipeline item
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}
                  method: PATCH
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline item not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}
                  method: PATCH
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Validation failed
                  details:
                    pipeline_item:
                    - is required
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}
                  method: PATCH
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INTERNAL_SERVER_ERROR
                  message: An unexpected error occurred
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}
                  method: PATCH
    delete:
      operationId: remove-pipeline-item
      summary: Remove item from pipeline
      description: Remove a conversation or contact from the pipeline
      security:
      - userApiKey: []
      responses:
        '200':
          description: Item removed successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    nullable: true
                    example: null
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline item removed successfully
              examples:
                success:
                  value:
                    success: true
                    data: null
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Pipeline item removed successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid pipeline item ID format
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}
                  method: DELETE
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid or missing authentication token
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}
                  method: DELETE
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: You do not have permission to remove this pipeline item
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}
                  method: DELETE
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline item not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}
                  method: DELETE
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INTERNAL_SERVER_ERROR
                  message: An unexpected error occurred
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}
                  method: DELETE
  /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/move_to_stage:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      required: true
      schema:
        type: string
    patch:
      operationId: move-item-to-stage
      summary: Move item to a different stage
      security:
      - userApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - new_stage_id
              properties:
                new_stage_id:
                  type: string
                  format: uuid
                notes:
                  type: string
                  description: Optional notes for the movement
      responses:
        '200':
          description: Item moved successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: '#/components/schemas/pipeline_item'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline item moved successfully
              examples:
                success:
                  value:
                    success: true
                    data:
                      id: 990e8400-e29b-41d4-a716-446655440004
                      pipeline_id: 550e8400-e29b-41d4-a716-446655440000
                      pipeline_stage_id: 880e8400-e29b-41d4-a716-446655440003
                      item_type: conversation
                      item_id: 880e8400-e29b-41d4-a716-446655440003
                      custom_fields: {}
                      created_at: '2024-01-15T10:30:00Z'
                      updated_at: '2024-01-15T10:35:00Z'
                    meta:
                      timestamp: '2024-01-15T10:35:00Z'
                    message: Pipeline item moved successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid stage ID format
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/move_to_stage
                  method: PATCH
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid or missing authentication token
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/move_to_stage
                  method: PATCH
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: You do not have permission to move items in this pipeline
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/move_to_stage
                  method: PATCH
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline item or stage not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/move_to_stage
                  method: PATCH
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Validation failed
                  details:
                    new_stage_id:
                    - is required
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/move_to_stage
                  method: PATCH
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INTERNAL_SERVER_ERROR
                  message: An unexpected error occurred
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/move_to_stage
                  method: PATCH
  /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/update_custom_fields:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      required: true
      schema:
        type: string
    patch:
      operationId: update-item-custom-fields
      summary: Update item custom fields
      security:
      - userApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - custom_fields
              properties:
                custom_fields:
                  type: object
      responses:
        '200':
          description: Custom fields updated successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: '#/components/schemas/pipeline_item'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline item custom fields updated successfully
              examples:
                success:
                  value:
                    success: true
                    data:
                      id: 990e8400-e29b-41d4-a716-446655440004
                      pipeline_id: 550e8400-e29b-41d4-a716-446655440000
                      pipeline_stage_id: 770e8400-e29b-41d4-a716-446655440002
                      item_type: conversation
                      item_id: 880e8400-e29b-41d4-a716-446655440003
                      custom_fields:
                        deal_value: 5000.0
                        expected_close_date: '2024-02-15'
                      created_at: '2024-01-15T10:30:00Z'
                      updated_at: '2024-01-15T10:35:00Z'
                    meta:
                      timestamp: '2024-01-15T10:35:00Z'
                    message: Pipeline item custom fields updated successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid request data
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/update_custom_fields
                  method: PATCH
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: UNAUTHORIZED
                  message: Invalid or missing authentication token
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/update_custom_fields
                  method: PATCH
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: FORBIDDEN
                  message: You do not have permission to update this pipeline item
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/update_custom_fields
                  method: PATCH
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline item not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/update_custom_fields
                  method: PATCH
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Validation failed
                  details:
                    custom_fields:
                    - is required
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/update_custom_fields
                  method: PATCH
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: INTERNAL_SERVER_ERROR
                  message: An unexpected error occurred
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{id}/update_custom_fields
                  method: PATCH
components:
  schemas:
    ErrorResponse:
      type: object
      required:
      - success
      - error
      - meta
      properties:
        success:
          type: boolean
          example: false
        error:
          type: object
          required:
          - code
          - message
          properties:
            code:
              type: string
              example: VALIDATION_ERROR
            message:
              type: string
              example: Validation failed
            details:
              type: object
              additionalProperties: true
              nullable: true
        meta:
          type: object
          required:
          - timestamp
          - path
          - method
          properties:
            timestamp:
              type: string
              format: date-time
              example: '2024-01-15T10:30:00Z'
            path:
              type: string
              example: /public/api/v1/inboxes/{inbox_identifier}/contacts
            method:
              type: string
              example: POST
    contact:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        email:
          type: string
          nullable: true
        phone_number:
          type: string
          nullable: true
        account_id:
          type: string
          format: uuid
        custom_attributes:
          type: object
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    conversation:
      type: object
      properties:
        id:
          type: string
          format: uuid
        display_id:
          type: string
          format: uuid
        status:
          type: string
          enum:
          - open
          - resolved
          - pending
          - snoozed
        contact_id:
          type: string
          format: uuid
        inbox_id:
          type: string
          format: uuid
        assignee_id:
          type: string
          format: uuid
          nullable: true
        team_id:
          type: string
          format: uuid
          nullable: true
        account_id:
          type: string
          format: uuid
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        last_activity_at:
          type: string
          format: date-time
        contact:
          $ref: '#/components/schemas/contact'
        assignee:
          $ref: '#/components/schemas/user'
          nullable: true
        inbox:
          type: object
          properties:
            id:
              type: string
              format: uuid
            channel_id:
              type: string
              format: uuid
            name:
              type: string
            channel_type:
              type: string
            enable_auto_assignment:
              type: boolean
            greeting_enabled:
              type: boolean
            greeting_message:
              type: string
              nullable: true
            working_hours_enabled:
              type: boolean
            out_of_office_message:
              type: string
              nullable: true
            timezone:
              type: string
            enable_email_collect:
              type: boolean
            csat_survey_enabled:
              type: boolean
            allow_messages_after_resolved:
              type: boolean
            auto_assignment_config:
              type: object
              additionalProperties: true
            lock_to_single_conversation:
              type: boolean
            csat_config:
              type: object
              additionalProperties: true
            sender_name_type:
              type: string
            business_name:
              type: string
              nullable: true
            display_name:
              type: string
            default_conversation_status:
              type: string
              nullable: true
            avatar_url:
              type: string
            working_hours:
              type: array
              items:
                type: object
                properties:
                  day_of_week:
                    type: integer
                  closed_all_day:
                    type: boolean
                  open_hour:
                    type: integer
                    nullable: true
                  open_minutes:
                    type: integer
                    nullable: true
                  close_hour:
                    type: integer
                    nullable: true
                  close_minutes:
                    type: integer
                    nullable: true
                  open_all_day:
                    type: boolean
            created_at:
              type: integer
            updated_at:
              type: integer
            provider:
              type: string
    pipeline_item:
      type: object
      properties:
        id:
          type: string
          format: uuid
        pipeline_id:
          type: string
          format: uuid
        pipeline_stage_id:
          type: string
          format: uuid
        conversation_id:
          type: string
          format: uuid
          nullable: true
        contact_id:
          type: string
          format: uuid
          nullable: true
        assigned_by_id:
          type: string
          format: uuid
          nullable: true
        custom_fields:
          type: object
          description: Custom field values including services, currency, etc.
        entered_at:
          type: string
          format: date-time
        completed_at:
          type: string
          format: date-time
          nullable: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        is_lead:
          type: boolean
          description: True if contact-based (lead), false if conversation-based (deal)
        pipeline_stage:
          $ref: '#/components/schemas/pipeline_stage'
        conversation:
          $ref: '#/components/schemas/conversation'
          nullable: true
        contact:
          $ref: '#/components/schemas/contact'
          nullable: true
        tasks:
          type: array
          items:
            $ref: '#/components/schemas/pipeline_task'
        pending_tasks_count:
          type: integer
        overdue_tasks_count:
          type: integer
        completed_tasks_count:
          type: integer
        services_total_value:
          type: number
          description: Sum of all service values
    pipeline_stage:
      type: object
      properties:
        id:
          type: string
          format: uuid
        pipeline_id:
          type: string
          format: uuid
        name:
          type: string
        color:
          type: string
          pattern: ^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$
        position:
          type: integer
        stage_type:
          type: integer
        automation_rules:
          type: object
        custom_fields:
          type: object
          properties:
            attributes:
              type: array
              items:
                type: string
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        item_count:
          type: integer
          description: Number of items in this stage
        items:
          type: array
          description: List of pipeline items in this stage
          items:
            $ref: '#/components/schemas/pipeline_item'
    pipeline_task:
      type: object
      properties:
        id:
          type: string
          format: uuid
        pipeline_item_id:
          type: string
          format: uuid
        account_id:
          type: string
          format: uuid
        title:
          type: string
          maxLength: 255
        description:
          type: string
          nullable: true
        task_type:
          type: string
          enum:
          - call
          - email
          - meeting
          - follow_up
          - note
          - other
        status:
          type: string
          enum:
          - pending
          - completed
          - cancelled
          - overdue
        priority:
          type: string
          enum:
          - low
          - medium
          - high
          - urgent
        due_date:
          type: string
          format: date-time
          nullable: true
        completed_at:
          type: string
          format: date-time
          nullable: true
        created_by_id:
          type: string
          format: uuid
        assigned_to_id:
          type: string
          format: uuid
          nullable: true
        parent_task_id:
          type: string
          format: uuid
          nullable: true
        position:
          type: integer
          description: Position among siblings
        depth:
          type: integer
          description: Hierarchy depth (0=root, 1=subtask, 2=sub-subtask)
        metadata:
          type: object
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        created_by:
          $ref: '#/components/schemas/user'
        assigned_to:
          $ref: '#/components/schemas/user'
          nullable: true
        parent_task:
          $ref: '#/components/schemas/pipeline_task'
          nullable: true
        subtasks:
          type: array
          items:
            $ref: '#/components/schemas/pipeline_task'
        subtask_count:
          type: integer
        overdue:
          type: boolean
        due_soon:
          type: boolean
        days_until_due:
          type: integer
          nullable: true
        hours_until_due:
          type: number
          nullable: true
    user:
      type: object
      properties:
        id:
          type: string
          format: uuid
        name:
          type: string
        email:
          type: string
        avatar_url:
          type: string
          nullable: true
        available_name:
          type: string
          description: Display name for the user
  securitySchemes:
    userApiKey:
      type: apiKey
      in: header
      name: api_access_token
    ApiAccessToken:
      type: apiKey
      in: header
      name: api_access_token
      description: API access token for user authentication
