openapi: 3.0.4
info:
  title: Evolution Foundation - CRM Service - AI Agent Products
  description: |
    Attach and detach products to AI agents. The agent's config (which lives in
    evo-ai-core-service) is automatically synced when products are
    attached/detached, so the agent picks up the new catalog on its next
    conversation.

    Available starting `v1.0.0-rc3`.

    **Note:** This OpenAPI spec was generated from the controller as part of the rc3 release. Schemas reflect the controller surface but request/response examples may need refinement based on real payloads.
  version: 1.0.0
servers:
- url: https://api.evoai.app
  description: Production server
- url: http://localhost:3000
  description: Development server
paths:
  /api/v1/ai_agents/{ai_agent_id}/products:
    parameters:
    - name: ai_agent_id
      in: path
      required: true
      schema: { type: string, format: uuid }
      description: ID of the AI agent
    get:
      operationId: list-agent-products
      summary: List Attached Products
      description: Lists all products currently attached to the AI agent. Requires `agents.read`.
      security:
      - userApiKey: []
      responses:
        '200':
          description: Products retrieved successfully
          content:
            application/json:
              schema:
                type: object
                required: [success, data, meta, message]
                properties:
                  success: { type: boolean, example: true }
                  data:
                    type: array
                    description: List of attached products
                    items:
                      type: object
                      properties:
                        ai_agent_id: { type: string, format: uuid }
                        product_id: { type: string, format: uuid }
                        product:
                          type: object
                          description: Embedded product (optional, depending on serializer)
                          properties:
                            id: { type: string, format: uuid }
                            name: { type: string }
                            status: { type: string }
                  meta:
                    type: object
                    properties:
                      timestamp: { type: string, format: date-time }
                  message: { type: string }
        '404':
          $ref: '#/components/responses/NotFound'
    post:
      operationId: attach-products-to-agent
      summary: Attach Products
      description: |
        Attaches one or more products to the agent. After the attach succeeds,
        the service triggers `Ai::AgentProductSyncService` to update the
        agent's config in evo-ai-core-service.

        Requires `agents.update`.
      security:
      - userApiKey: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
              - type: object
                required: [product_ids]
                properties:
                  product_ids:
                    type: array
                    items: { type: string, format: uuid }
                    description: List of product IDs to attach (preferred)
              - type: object
                required: [product_id]
                properties:
                  product_id:
                    type: string
                    format: uuid
                    description: Single product ID (legacy shape)
      responses:
        '200':
          description: Products attached successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success: { type: boolean }
                  data:
                    type: object
                    properties:
                      ai_agent_id: { type: string, format: uuid }
                      attached:
                        type: array
                        items: { type: string, format: uuid }
                        description: IDs of products that were attached in this request
                  message: { type: string }
        '400':
          description: Bad request — missing product_ids/product_id
        '404':
          description: AI agent or one of the products not found

  /api/v1/ai_agents/{ai_agent_id}/products/{id}:
    parameters:
    - name: ai_agent_id
      in: path
      required: true
      schema: { type: string, format: uuid }
    - name: id
      in: path
      required: true
      schema: { type: string, format: uuid }
      description: ID of the product to detach
    delete:
      operationId: detach-product-from-agent
      summary: Detach Product
      description: |
        Removes the binding between the agent and the given product. The
        agent's config in evo-ai-core-service is re-synced after detach.

        Requires `agents.update`.
      security:
      - userApiKey: []
      responses:
        '200':
          description: Product detached successfully
        '404':
          description: Binding not found

components:
  securitySchemes:
    userApiKey:
      type: apiKey
      in: header
      name: api_access_token
  responses:
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            type: object
            properties:
              success: { type: boolean, example: false }
              message: { type: string, example: "Not Found" }
