openapi: 3.0.4
info:
  title: Evolution Foundation - CRM Service - Pipeline Tasks
  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/{pipeline_item_id}/tasks:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: pipeline_item_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: status
      in: query
      required: false
      schema:
        type: string
        enum:
        - pending
        - completed
        - cancelled
        - overdue
    - name: task_type
      in: query
      required: false
      schema:
        type: string
        enum:
        - call
        - email
        - meeting
        - follow_up
        - note
        - other
    - name: priority
      in: query
      required: false
      schema:
        type: string
        enum:
        - low
        - medium
        - high
        - urgent
    - name: assigned_to_id
      in: query
      required: false
      schema:
        type: string
        format: uuid
    - name: hierarchy
      in: query
      required: false
      schema:
        type: string
        enum:
        - all
        - root
        default: root
      description: Include subtasks (all) or only root tasks (root)
    get:
      operationId: list-pipeline-tasks
      summary: List tasks for a pipeline item
      description: Get all tasks associated with a pipeline item (deal/lead)
      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_task'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline tasks retrieved successfully
              examples:
                success:
                  value:
                    success: true
                    data: []
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Pipeline tasks retrieved 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/{pipeline_item_id}/tasks
                  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/{pipeline_item_id}/tasks
                  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/{pipeline_item_id}/tasks
                  method: GET
        '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/{pipeline_item_id}/tasks
                  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/{pipeline_item_id}/tasks
                  method: GET
    post:
      operationId: create-pipeline-task
      summary: Create a new task
      description: Add a task to a pipeline item
      security:
      - userApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - task
              properties:
                task:
                  type: object
                  required:
                  - title
                  properties:
                    title:
                      type: string
                      maxLength: 255
                    description:
                      type: string
                    task_type:
                      type: string
                      enum:
                      - call
                      - email
                      - meeting
                      - follow_up
                      - note
                      - other
                      default: call
                    due_date:
                      type: string
                      format: date-time
                    assigned_to_id:
                      type: string
                      format: uuid
                    priority:
                      type: string
                      enum:
                      - low
                      - medium
                      - high
                      - urgent
                      default: low
                    parent_task_id:
                      type: string
                      format: uuid
                      description: Parent task ID if creating a subtask
                    metadata:
                      type: object
      responses:
        '200':
          description: Task created successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: '#/components/schemas/pipeline_task'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline task created successfully
              examples:
                success:
                  value:
                    success: true
                    data:
                      id: aa0e8400-e29b-41d4-a716-446655440005
                      pipeline_id: 550e8400-e29b-41d4-a716-446655440000
                      pipeline_item_id: 990e8400-e29b-41d4-a716-446655440004
                      title: Follow up call
                      description: Call customer to discuss proposal
                      task_type: call
                      status: pending
                      priority: high
                      due_date: '2024-01-20T14:00:00Z'
                      assigned_to_id: 660e8400-e29b-41d4-a716-446655440001
                      parent_task_id: null
                      metadata: {}
                      created_at: '2024-01-15T10:30:00Z'
                      updated_at: '2024-01-15T10:30:00Z'
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Pipeline task created 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/{pipeline_item_id}/tasks
                  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/{pipeline_item_id}/tasks
                  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 create tasks in this pipeline
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{pipeline_item_id}/tasks
                  method: POST
        '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/{pipeline_item_id}/tasks
                  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:
                    task:
                    - is required
                    task.title:
                    - is required
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_items/{pipeline_item_id}/tasks
                  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/{pipeline_item_id}/tasks
                  method: POST
  /api/v1/pipelines/{pipeline_id}/pipeline_tasks/statistics:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    get:
      operationId: get-tasks-statistics
      summary: Get task statistics
      description: Get aggregated statistics for all tasks in the pipeline
      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:
                        type: integer
                        example: 50
                      pending:
                        type: integer
                        example: 30
                      completed:
                        type: integer
                        example: 15
                      overdue:
                        type: integer
                        example: 5
                      due_today:
                        type: integer
                        example: 3
                      due_this_week:
                        type: integer
                        example: 10
                      by_type:
                        type: object
                        additionalProperties:
                          type: integer
                        example:
                          call: 20
                          email: 15
                          meeting: 10
                          follow_up: 5
                      by_assignee:
                        type: object
                        additionalProperties:
                          type: integer
                        example:
                          660e8400-e29b-41d4-a716-446655440001: 25
                          770e8400-e29b-41d4-a716-446655440002: 15
                          880e8400-e29b-41d4-a716-446655440003: 10
                      by_priority:
                        type: object
                        additionalProperties:
                          type: integer
                        example:
                          low: 10
                          medium: 20
                          high: 15
                          urgent: 5
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Task statistics retrieved successfully
              examples:
                success:
                  value:
                    success: true
                    data:
                      total: 50
                      pending: 30
                      completed: 15
                      overdue: 5
                      due_today: 3
                      due_this_week: 10
                      by_type:
                        call: 20
                        email: 15
                        meeting: 10
                        follow_up: 5
                      by_assignee:
                        660e8400-e29b-41d4-a716-446655440001: 25
                        770e8400-e29b-41d4-a716-446655440002: 15
                        880e8400-e29b-41d4-a716-446655440003: 10
                      by_priority:
                        low: 10
                        medium: 20
                        high: 15
                        urgent: 5
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Task 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_tasks/statistics
                  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_tasks/statistics
                  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_tasks/statistics
                  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_tasks/statistics
                  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_tasks/statistics
                  method: GET
  /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    get:
      operationId: get-pipeline-task
      summary: Get a single task
      description: Get detailed information about a specific task including subtasks
      security:
      - userApiKey: []
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: '#/components/schemas/pipeline_task'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline task retrieved successfully
              examples:
                success:
                  value:
                    success: true
                    data:
                      id: aa0e8400-e29b-41d4-a716-446655440005
                      pipeline_id: 550e8400-e29b-41d4-a716-446655440000
                      pipeline_item_id: 990e8400-e29b-41d4-a716-446655440004
                      title: Follow up call
                      description: Call customer to discuss proposal
                      task_type: call
                      status: pending
                      priority: high
                      due_date: '2024-01-20T14:00:00Z'
                      assigned_to_id: 660e8400-e29b-41d4-a716-446655440001
                      parent_task_id: null
                      metadata: {}
                      created_at: '2024-01-15T10:30:00Z'
                      updated_at: '2024-01-15T10:30:00Z'
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Pipeline task retrieved successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid task ID format
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}
                  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_tasks/{id}
                  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 task
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}
                  method: GET
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline task not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}
                  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_tasks/{id}
                  method: GET
    patch:
      operationId: update-pipeline-task
      summary: Update a task
      description: Update task details (cannot update completed tasks)
      security:
      - userApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - task
              properties:
                task:
                  type: object
                  properties:
                    title:
                      type: string
                    description:
                      type: string
                    task_type:
                      type: string
                      enum:
                      - call
                      - email
                      - meeting
                      - follow_up
                      - note
                      - other
                    due_date:
                      type: string
                      format: date-time
                    assigned_to_id:
                      type: string
                      format: uuid
                    priority:
                      type: string
                      enum:
                      - low
                      - medium
                      - high
                      - urgent
                    metadata:
                      type: object
      responses:
        '200':
          description: Task updated successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    $ref: '#/components/schemas/pipeline_task'
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline task updated successfully
              examples:
                success:
                  value:
                    success: true
                    data:
                      id: aa0e8400-e29b-41d4-a716-446655440005
                      pipeline_id: 550e8400-e29b-41d4-a716-446655440000
                      pipeline_item_id: 990e8400-e29b-41d4-a716-446655440004
                      title: Updated task title
                      description: Updated task description
                      task_type: meeting
                      status: pending
                      priority: urgent
                      due_date: '2024-01-25T14:00:00Z'
                      assigned_to_id: 660e8400-e29b-41d4-a716-446655440001
                      parent_task_id: null
                      metadata: {}
                      created_at: '2024-01-15T10:30:00Z'
                      updated_at: '2024-01-15T10:35:00Z'
                    meta:
                      timestamp: '2024-01-15T10:35:00Z'
                    message: Pipeline task updated successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Cannot update completed task
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{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_tasks/{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 task
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}
                  method: PATCH
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline task not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{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:
                    task:
                    - is required
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{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_tasks/{id}
                  method: PATCH
    delete:
      operationId: delete-pipeline-task
      summary: Delete a task
      description: Delete a task and optionally its subtasks
      security:
      - userApiKey: []
      parameters:
      - name: delete_subtasks
        in: query
        required: false
        schema:
          type: string
          enum:
          - 'true'
          - 'false'
        description: Set to 'true' to delete task with its subtasks
      responses:
        '200':
          description: Task deleted 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 task deleted successfully
              examples:
                success:
                  value:
                    success: true
                    data: null
                    meta:
                      timestamp: '2024-01-15T10:30:00Z'
                    message: Pipeline task deleted successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid task ID format
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{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_tasks/{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 delete this task
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}
                  method: DELETE
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline task not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}
                  method: DELETE
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Task has subtasks. Set delete_subtasks=true to delete with subtasks
                  details:
                    delete_subtasks:
                    - Task has subtasks that must be deleted first
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{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_tasks/{id}
                  method: DELETE
  /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}/add_subtask:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    post:
      operationId: add-subtask
      summary: Add a subtask to a task
      description: Create a subtask under an existing task (max 3 hierarchy levels)
      security:
      - userApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - task
              properties:
                task:
                  type: object
                  required:
                  - title
                  properties:
                    title:
                      type: string
                    description:
                      type: string
                    task_type:
                      type: string
                      enum:
                      - call
                      - email
                      - meeting
                      - follow_up
                      - note
                      - other
                    due_date:
                      type: string
                      format: date-time
                    assigned_to_id:
                      type: string
                      format: uuid
                    priority:
                      type: string
                      enum:
                      - low
                      - medium
                      - high
                      - urgent
                    metadata:
                      type: object
      responses:
        '201':
          description: Subtask created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/pipeline_task'
                  message:
                    type: string
        '422':
          $ref: '#/components/responses/validation_error'
  /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}/cancel:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    post:
      operationId: cancel-task
      summary: Cancel a task
      security:
      - userApiKey: []
      responses:
        '200':
          description: Task cancelled successfully
  /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}/complete:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    post:
      operationId: complete-task
      summary: Mark task as completed
      description: Complete a task (also completes all its subtasks)
      security:
      - userApiKey: []
      responses:
        '200':
          description: Task completed successfully
          content:
            application/json:
              schema:
                type: object
                required:
                - success
                - data
                - meta
                - message
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    allOf:
                    - $ref: '#/components/schemas/pipeline_task'
                    - type: object
                      properties:
                        descendants_completed_count:
                          type: integer
                          description: Number of subtasks completed
                          example: 3
                  meta:
                    type: object
                    properties:
                      timestamp:
                        type: string
                        format: date-time
                        description: Response timestamp
                        example: '2024-01-15T10:30:00Z'
                  message:
                    type: string
                    example: Pipeline task completed successfully
              examples:
                success:
                  value:
                    success: true
                    data:
                      id: aa0e8400-e29b-41d4-a716-446655440005
                      pipeline_id: 550e8400-e29b-41d4-a716-446655440000
                      pipeline_item_id: 990e8400-e29b-41d4-a716-446655440004
                      title: Follow up call
                      description: Call customer to discuss proposal
                      task_type: call
                      status: completed
                      priority: high
                      due_date: '2024-01-20T14:00:00Z'
                      assigned_to_id: 660e8400-e29b-41d4-a716-446655440001
                      parent_task_id: null
                      metadata: {}
                      descendants_completed_count: 3
                      created_at: '2024-01-15T10:30:00Z'
                      updated_at: '2024-01-15T10:35:00Z'
                    meta:
                      timestamp: '2024-01-15T10:35:00Z'
                    message: Pipeline task completed successfully
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: BAD_REQUEST
                  message: Invalid task ID format
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}/complete
                  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_tasks/{id}/complete
                  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 complete this task
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}/complete
                  method: POST
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: NOT_FOUND
                  message: Pipeline task not found
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}/complete
                  method: POST
        '422':
          description: Unprocessable Entity
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: VALIDATION_ERROR
                  message: Task is already completed
                  details:
                    status:
                    - Task is already in completed status
                meta:
                  timestamp: '2024-01-15T10:30:00Z'
                  path: /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}/complete
                  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_tasks/{id}/complete
                  method: POST
  /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}/move:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    patch:
      operationId: move-task
      summary: Move task to a different parent
      description: Change the parent of a task or promote to root level
      security:
      - userApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                new_parent_id:
                  type: string
                  format: uuid
                  nullable: true
                  description: New parent task ID (null to make it a root task)
                new_position:
                  type: integer
                  description: Optional position in the new parent's subtasks
      responses:
        '200':
          description: Task moved successfully
        '422':
          $ref: '#/components/responses/validation_error'
  /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}/reopen:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    post:
      operationId: reopen-task
      summary: Reopen a completed/cancelled task
      description: Reopen a task (also reopens all its subtasks)
      security:
      - userApiKey: []
      responses:
        '200':
          description: Task reopened successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    allOf:
                    - $ref: '#/components/schemas/pipeline_task'
                    - type: object
                      properties:
                        descendants_reopened_count:
                          type: integer
                  message:
                    type: string
  /api/v1/pipelines/{pipeline_id}/pipeline_tasks/{id}/reorder:
    parameters:
    - name: pipeline_id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    - name: id
      in: path
      required: true
      schema:
        type: string
        format: uuid
    patch:
      operationId: reorder-task
      summary: Change task position among siblings
      description: Reorder a task within its current parent's subtasks
      security:
      - userApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - position
              properties:
                position:
                  type: integer
                  description: New position (0-based)
      responses:
        '200':
          description: Task reordered successfully
        '422':
          $ref: '#/components/responses/validation_error'
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
    error_response:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
        details:
          oneOf:
          - type: string
          - type: array
            items:
              type: string
          - type: object
    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
  responses:
    validation_error:
      description: Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/error_response'
