openapi: 3.0.0
info:
  title: Financbase Admin Dashboard API
  version: 2.0.0
  description: >-
    A comprehensive financial management platform API with advanced automation,
    integrations, and analytics capabilities.
  contact:
    name: Financbase Support
    email: support@financbase.com
  license:
    name: Proprietary
    url: https://financbase.com/license
servers:
  - url: http://localhost:3000
    description: Development server
  - url: https://app.financbase.com
    description: Production server
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Clerk session token obtained from getToken()
security:
  - BearerAuth: []
tags:
  - name: Authentication
    description: Authentication and token validation endpoints
  - name: Dashboard
    description: Dashboard metrics and data export
  - name: Financial
    description: Financial management - invoices, expenses, transactions
  - name: Analytics
    description: Analytics and reporting endpoints
  - name: Integrations
    description: Third-party integrations and webhooks
  - name: Workflows
    description: Workflow automation and execution
  - name: AI
    description: AI-powered features and analysis
paths:
  /api/ab-tests/track:
    post:
      summary: Create or submit Track
      description: /ab-tests/track endpoint.
      tags:
        - Ab-Tests
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/ab-tests/variant:
    post:
      summary: Create or submit Variant
      description: /ab-tests/variant endpoint.
      tags:
        - Ab-Tests
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/access-management/folders/{folderId}/invite:
    post:
      summary: Create or submit Invite
      description: /access-management/folders/{folderId}/invite endpoint.
      tags:
        - Access-Management
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/access-management/folders/{folderId}/members/{memberId}:
    patch:
      summary: Update resource
      description: /access-management/folders/{folderId}/members/{memberId} endpoint.
      tags:
        - Access-Management
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /access-management/folders/{folderId}/members/{memberId} endpoint.
      tags:
        - Access-Management
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/access-management/folders/{folderId}:
    get:
      summary: Get resource
      description: /access-management/folders/{folderId} endpoint.
      tags:
        - Access-Management
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /accounts/{id}:
    get:
      summary: Get account by ID
      description: Returns a single financial account by ID for the authenticated user.
      tags:
        - accounts
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Account ID
      responses:
        '200':
          description: Account object in body.account
        '401':
          description: Unauthorized
        '404':
          description: Account not found
        '500':
          description: Internal server error
    put:
      summary: Update account
      description: >-
        Updates an existing financial account. Accepts accountName, accountType,
        bankName, currency, etc.
      tags:
        - accounts
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Account ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                accountName:
                  type: string
                accountType:
                  type: string
                  enum:
                    - checking
                    - savings
                    - credit_card
                    - investment
                    - loan
                    - other
                bankName:
                  type: string
                currency:
                  type: string
      responses:
        '200':
          description: Updated account in body.account
        '400':
          description: Invalid JSON or validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    delete:
      summary: Delete account
      description: Deletes a financial account for the authenticated user.
      tags:
        - accounts
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Account ID
      responses:
        '200':
          description: Success
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /accounts/{id}/sync:
    post:
      summary: Sync account
      description: >-
        Triggers a sync for the given account (import transactions from linked
        source). Requires authentication.
      tags:
        - accounts
        - sync
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Account ID
      responses:
        '200':
          description: Sync result with success
          message: null
          data (syncId: null
          status: null
          transactionsImported: null
          lastSyncAt): null
        '400':
          description: Account ID required
        '401':
          description: Unauthorized
        '404':
          description: User not found
        '500':
          description: Internal server error
  /accounts/balances:
    get:
      summary: Get account balances
      description: >-
        Returns balances grouped by account type (checking, savings, investment,
        credit) with 30-day change for the authenticated user.
      tags:
        - accounts
        - financial
      responses:
        '200':
          description: Object with balances key (checking
          savings: null
          investment: null
          credit each with balance: null
          change: null
          accountNumber: null
          bankName): null
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/accounts/reconcile:
    get:
      summary: Get Reconcile
      description: /accounts/reconcile endpoint.
      tags:
        - Accounts
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Reconcile
      description: /accounts/reconcile endpoint.
      tags:
        - Accounts
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/accounts:
    get:
      summary: Get list of financial accounts
      description: >-
        Retrieves a paginated list of financial accounts (checking, savings,
        credit cards, etc.) with optional filtering
      tags:
        - Financial
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
          description: Page number for pagination
        - in: query
          name: limit
          schema:
            type: integer
            default: 20
          description: Number of items per page
        - in: query
          name: search
          schema:
            type: string
          description: Search term for account name or bank name
        - in: query
          name: accountType
          schema:
            type: string
            enum:
              - checking
              - savings
              - credit_card
              - investment
              - loan
              - other
          description: Filter accounts by type
        - in: query
          name: status
          schema:
            type: string
            enum:
              - active
              - inactive
              - closed
              - suspended
          description: Filter accounts by status
      responses:
        '200':
          description: Accounts retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: account_123
                        accountName:
                          type: string
                          example: Business Checking
                        accountType:
                          type: string
                          enum:
                            - checking
                            - savings
                            - credit_card
                            - investment
                            - loan
                            - other
                        balance:
                          type: number
                          example: 12500
                  pagination:
                    type: object
                    properties:
                      page:
                        type: integer
                      limit:
                        type: integer
                      total:
                        type: integer
                      pages:
                        type: integer
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Create a new financial account
      description: >-
        Creates a new financial account (checking, savings, credit card,
        investment, loan, etc.)
      tags:
        - Financial
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - accountName
                - accountType
              properties:
                accountName:
                  type: string
                  example: Business Checking Account
                accountType:
                  type: string
                  enum:
                    - checking
                    - savings
                    - credit_card
                    - investment
                    - loan
                    - other
                  example: checking
                bankName:
                  type: string
                  example: First National Bank
                accountNumber:
                  type: string
                lastFourDigits:
                  type: string
                  example: '1234'
                routingNumber:
                  type: string
                currency:
                  type: string
                  default: USD
                openingBalance:
                  type: number
                  default: 0
                creditLimit:
                  type: number
                  description: Credit limit for credit cards
                interestRate:
                  type: number
                  description: Interest rate for loans or savings
                notes:
                  type: string
      responses:
        '201':
          description: Account created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  account:
                    type: object
                    properties:
                      id:
                        type: string
                        example: account_123
                      accountName:
                        type: string
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/accounts/stats:
    get:
      summary: Get Stats
      description: /accounts/stats endpoint.
      tags:
        - Accounts
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/accounts/sync/history:
    get:
      summary: Get History
      description: /accounts/sync/history endpoint.
      tags:
        - Accounts
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/accounts/sync:
    post:
      summary: Create or submit Sync
      description: /accounts/sync endpoint.
      tags:
        - Accounts
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/accounts/sync/status:
    get:
      summary: Get Status
      description: /accounts/sync/status endpoint.
      tags:
        - Accounts
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/accounts/unified:
    get:
      summary: Get Unified
      description: /accounts/unified endpoint.
      tags:
        - Accounts
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/admin/careers/{id}:
    get:
      summary: Get job posting by ID (admin)
      description: Returns a single job posting. Requires CAREERS_VIEW or manager role.
      tags:
        - Admin
        - Careers
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Job posting ID
      responses:
        '200':
          description: Job posting details
        '400':
          description: Invalid job ID
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Job posting not found
    patch:
      summary: Update job posting (admin)
      description: >-
        Updates a job posting. Partial body (title, department, location, type,
        experience, description, status, isFeatured, etc.). Requires
        CAREERS_EDIT or manager role.
      tags:
        - Admin
        - Careers
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Job posting ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                title:
                  type: string
                department:
                  type: string
                location:
                  type: string
                type:
                  type: string
                experience:
                  type: string
                description:
                  type: string
                fullDescription:
                  type: string
                requirements:
                  type: array
                  items:
                    type: string
                status:
                  type: string
                  enum:
                    - draft
                    - published
                    - closed
                    - archived
                isFeatured:
                  type: boolean
      responses:
        '200':
          description: Updated job posting
        '400':
          description: Validation error or invalid job ID
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Job posting not found
    delete:
      summary: Delete job posting (admin)
      description: >-
        Deletes or archives a job posting. Requires CAREERS_DELETE or manager
        role.
      tags:
        - Admin
        - Careers
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Job posting ID
      responses:
        '200':
          description: Job posting deleted
        '400':
          description: Invalid job ID
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Job posting not found
  /api/admin/careers:
    get:
      summary: List job postings (admin)
      description: >-
        Returns job postings with optional filters (status, department).
        Requires CAREERS_VIEW or manager role.
      tags:
        - Admin
        - Careers
      parameters:
        - in: query
          name: status
          schema:
            type: string
        - in: query
          name: department
          schema:
            type: string
      responses:
        '200':
          description: List of job postings
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
    post:
      summary: Create job posting (admin)
      description: >-
        Creates a new job posting. Body title, department, location, type,
        experience, description; optional fullDescription, requirements,
        responsibilities, qualifications, salary, benefits, status, isFeatured.
        Requires CAREERS_CREATE or manager role.
      tags:
        - Admin
        - Careers
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - title
                - department
                - location
                - type
                - experience
                - description
              properties:
                title:
                  type: string
                department:
                  type: string
                location:
                  type: string
                type:
                  type: string
                experience:
                  type: string
                description:
                  type: string
                fullDescription:
                  type: string
                requirements:
                  type: array
                  items:
                    type: string
                responsibilities:
                  type: array
                  items:
                    type: string
                qualifications:
                  type: array
                  items:
                    type: string
                salary:
                  type: string
                benefits:
                  type: array
                  items:
                    type: string
                status:
                  type: string
                  enum:
                    - draft
                    - published
                    - closed
                    - archived
                  default: draft
                isFeatured:
                  type: boolean
                  default: false
      responses:
        '200':
          description: Created job posting
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
  /api/admin/feature-flags/{key}:
    get:
      summary: Get feature flag by key (admin)
      description: Returns a single feature flag by key. Requires admin access.
      tags:
        - Admin
      parameters:
        - in: path
          name: key
          required: true
          schema:
            type: string
          description: Feature flag key
      responses:
        '200':
          description: Feature flag details
        '401':
          description: Unauthorized
        '403':
          description: Forbidden - admin required
        '404':
          description: Feature flag not found
    patch:
      summary: Update feature flag (admin)
      description: >-
        Updates a feature flag (name, description, enabled, rolloutPercentage,
        targetOrganizations, targetUsers, conditions, metadata). Requires admin
        access.
      tags:
        - Admin
      parameters:
        - in: path
          name: key
          required: true
          schema:
            type: string
          description: Feature flag key
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                description:
                  type: string
                enabled:
                  type: boolean
                rolloutPercentage:
                  type: number
                  minimum: 0
                  maximum: 100
                targetOrganizations:
                  type: array
                  items:
                    type: string
                targetUsers:
                  type: array
                  items:
                    type: string
                conditions:
                  type: object
                metadata:
                  type: object
      responses:
        '200':
          description: Updated feature flag
        '401':
          description: Unauthorized
        '403':
          description: Forbidden - admin required
        '404':
          description: Feature flag not found
    delete:
      summary: Delete feature flag (admin)
      description: Deletes a feature flag by key. Requires admin access.
      tags:
        - Admin
      parameters:
        - in: path
          name: key
          required: true
          schema:
            type: string
          description: Feature flag key
      responses:
        '200':
          description: Feature flag deleted
        '401':
          description: Unauthorized
        '403':
          description: Forbidden - admin required
        '404':
          description: Feature flag not found
  /api/admin/feature-flags:
    get:
      summary: List feature flags (admin)
      description: Returns all feature flags. Requires admin access.
      tags:
        - Admin
      responses:
        '200':
          description: List of feature flags
        '401':
          description: Unauthorized
        '403':
          description: Forbidden - admin required
    post:
      summary: Create feature flag (admin)
      description: >-
        Creates a new feature flag. Body key, name; optional description,
        enabled, rolloutPercentage, targetOrganizations, targetUsers,
        conditions, metadata. Requires admin access.
      tags:
        - Admin
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - key
                - name
              properties:
                key:
                  type: string
                  pattern: ^[a-z0-9_]+$
                name:
                  type: string
                description:
                  type: string
                enabled:
                  type: boolean
                rolloutPercentage:
                  type: number
                  minimum: 0
                  maximum: 100
                targetOrganizations:
                  type: array
                  items:
                    type: string
                targetUsers:
                  type: array
                  items:
                    type: string
                conditions:
                  type: object
                metadata:
                  type: object
      responses:
        '200':
          description: Created feature flag
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '403':
          description: Forbidden - admin required
  /admin/seed-dashboard:
    get:
      summary: Check dashboard data status
      description: >-
        Returns whether the authenticated user has seeded dashboard data
        (clients, invoices, expenses).
      tags:
        - admin
        - seed-dashboard
      responses:
        '200':
          description: Data status with hasData and details
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Seed dashboard data
      description: >-
        Seeds dashboard data for the authenticated user or for a provided
        userId/email (admin/testing). Optional body clearExisting, skipIfExists.
      tags:
        - admin
        - seed-dashboard
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                userId:
                  type: string
                email:
                  type: string
                clearExisting:
                  type: boolean
                  default: false
                skipIfExists:
                  type: boolean
                  default: true
      responses:
        '200':
          description: Success with data counts
        '401':
          description: Unauthorized
        '404':
          description: User not found (when email provided)
        '500':
          description: Internal server error
  /admin/services/health:
    get:
      summary: Get service health status
      description: >-
        Returns health status of all registered services (summary, services,
        discovery, registeredServices). Requires authentication.
      tags:
        - admin
        - services
      responses:
        '200':
          description: Health payload with success
          summary: null
          services: null
          discovery: null
          registeredServices: null
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /admin/services/metrics:
    get:
      summary: Get service performance metrics
      description: >-
        Returns performance metrics for all services or a single service when
        query param service is provided. Requires authentication.
      tags:
        - admin
        - services
      parameters:
        - in: query
          name: service
          schema:
            type: string
          description: Optional service name to filter metrics
      responses:
        '200':
          description: Metrics payload with success
          metrics: null
          summary: null
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/admin/subscription-rbac-mappings:
    get:
      summary: Get Subscription Rbac Mappings
      description: /admin/subscription-rbac-mappings endpoint.
      tags:
        - Admin
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/admin/support/analytics:
    get:
      summary: Get support ticket analytics (admin)
      description: >-
        Returns ticket analytics (counts, trends) for a date range. Query
        dateFrom, dateTo optional. Requires SUPPORT_TICKETS_MANAGE permission.
      tags:
        - Admin
        - Support
      parameters:
        - in: query
          name: dateFrom
          schema:
            type: string
            format: date-time
        - in: query
          name: dateTo
          schema:
            type: string
            format: date-time
      responses:
        '200':
          description: Ticket analytics (counts, by status, by priority, etc.)
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
  /api/admin/support/tickets/{id}/assign:
    post:
      summary: Assign support ticket (admin)
      description: >-
        Assigns or unassigns a ticket. Body assignedTo (string or null).
        Requires SUPPORT_TICKETS_MANAGE permission.
      tags:
        - Admin
        - Support
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Ticket ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                assignedTo:
                  type: string
                  nullable: true
      responses:
        '200':
          description: Updated ticket
        '400':
          description: Invalid ticket ID or assignedTo must be string or null
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
  /api/admin/support/tickets/{id}/messages:
    get:
      summary: List ticket messages (admin)
      description: >-
        Returns messages for a support ticket. Requires SUPPORT_TICKETS_MANAGE
        permission.
      tags:
        - Admin
        - Support
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Ticket ID
      responses:
        '200':
          description: List of messages
        '400':
          description: Invalid ticket ID
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Ticket not found
    post:
      summary: Add message to ticket (admin)
      description: >-
        Adds a message/reply to a support ticket. Body content (required).
        Requires SUPPORT_TICKETS_MANAGE permission.
      tags:
        - Admin
        - Support
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Ticket ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - content
              properties:
                content:
                  type: string
      responses:
        '200':
          description: Message added
        '400':
          description: Invalid ticket ID or missing content
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Ticket not found
  /api/admin/support/tickets/{id}:
    get:
      summary: Get support ticket by ID (admin)
      description: >-
        Returns a single support ticket. Requires SUPPORT_TICKETS_MANAGE
        permission.
      tags:
        - Admin
        - Support
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Ticket ID
      responses:
        '200':
          description: Ticket details
        '400':
          description: Invalid ticket ID
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Ticket not found
    patch:
      summary: Update support ticket (admin)
      description: >-
        Updates a support ticket (status, priority, assignedTo, etc.). Requires
        SUPPORT_TICKETS_MANAGE permission.
      tags:
        - Admin
        - Support
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Ticket ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                priority:
                  type: string
                assignedTo:
                  type: string
      responses:
        '200':
          description: Updated ticket
        '400':
          description: Invalid ticket ID
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Ticket not found
  /api/admin/support/tickets:
    get:
      summary: List support tickets (admin)
      description: >-
        Returns support tickets with optional filters (status, priority,
        category, assignedTo, userId, dateFrom, dateTo). Pagination via limit,
        offset. Requires SUPPORT_TICKETS_MANAGE permission.
      tags:
        - Admin
        - Support
      parameters:
        - in: query
          name: status
          schema:
            type: string
        - in: query
          name: priority
          schema:
            type: string
        - in: query
          name: category
          schema:
            type: string
        - in: query
          name: assignedTo
          schema:
            type: string
        - in: query
          name: userId
          schema:
            type: string
        - in: query
          name: dateFrom
          schema:
            type: string
            format: date-time
        - in: query
          name: dateTo
          schema:
            type: string
            format: date-time
        - in: query
          name: limit
          schema:
            type: integer
            default: 20
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
        - in: query
          name: sortBy
          schema:
            type: string
            default: createdAt
        - in: query
          name: sortOrder
          schema:
            type: string
            enum:
              - asc
              - desc
            default: desc
      responses:
        '200':
          description: List of tickets
        '401':
          description: Unauthorized
        '403':
          description: Forbidden - no permission to manage support tickets
    post:
      summary: Create support ticket (admin)
      description: >-
        Creates a new support ticket. Requires SUPPORT_TICKETS_MANAGE
        permission.
      tags:
        - Admin
        - Support
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                subject:
                  type: string
                description:
                  type: string
                priority:
                  type: string
                category:
                  type: string
                userId:
                  type: string
      responses:
        '200':
          description: Created ticket
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
  /api/admin/users/{id}/permissions:
    put:
      summary: Update user permissions (admin)
      description: >-
        Updates role and permissions for a user. Body permissions (array of
        strings), role (admin, user, viewer, manager). Requires ROLES_MANAGE
        permission.
      tags:
        - Admin
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: User ID (Clerk ID)
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                permissions:
                  type: array
                  items:
                    type: string
                role:
                  type: string
                  enum:
                    - admin
                    - user
                    - viewer
                    - manager
      responses:
        '200':
          description: User permissions updated
        '400':
          description: Invalid JSON or validation error
        '401':
          description: Unauthorized
        '403':
          description: Forbidden - no permission to manage roles
  /api/admin/users:
    get:
      summary: List users (admin)
      description: >-
        Returns all active users with permissions and metadata. Requires
        USERS_MANAGE permission.
      tags:
        - Admin
      responses:
        '200':
          description: >-
            List of users (id, email, name, role, permissions, financialAccess,
            lastActive)
        '401':
          description: Unauthorized
        '403':
          description: Forbidden - no permission to manage users
  /api/affiliate:
    get:
      summary: Get Affiliate
      description: /affiliate endpoint.
      tags:
        - Affiliate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Affiliate
      description: /affiliate endpoint.
      tags:
        - Affiliate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/agent:
    post:
      summary: Create or submit Agent
      description: /agent endpoint.
      tags:
        - Agent
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /ai-chat/sessions/{sessionId}/messages:
    get:
      summary: List AI chat messages
      description: Returns messages for the given AI chat session. Clerk auth.
      tags:
        - ai
        - ai-chat
      parameters:
        - in: path
          name: sessionId
          required: true
          schema:
            type: string
          description: Chat session ID
      responses:
        '200':
          description: List of messages
        '400':
          description: Missing sessionId
        '401':
          description: Unauthorized
        '404':
          description: Session not found
        '500':
          description: Internal server error
    post:
      summary: Send message to AI chat
      description: >-
        Sends a message, runs financial agent, persists and audits. Body content
        (string). Optional query stream=true for NDJSON streaming.
      tags:
        - ai
        - ai-chat
      parameters:
        - in: path
          name: sessionId
          required: true
          schema:
            type: string
          description: Chat session ID
        - in: query
          name: stream
          schema:
            type: boolean
          description: If true, response is NDJSON stream
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - content
              properties:
                content:
                  type: string
      responses:
        '200':
          description: Assistant message or stream
        '400':
          description: Invalid body or PII detected
        '401':
          description: Unauthorized
        '404':
          description: Session not found
        '429':
          description: Rate limit exceeded
        '500':
          description: Internal server error
  /ai-chat/sessions:
    post:
      summary: Create or resume AI chat session
      description: >-
        Creates a new AI chat session or resumes one by sessionToken. Clerk
        auth, 24h expiry. Returns sessionId, sessionToken, expiresAt.
      tags:
        - ai
        - ai-chat
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                sessionToken:
                  type: string
                  description: Optional; resume existing session
      responses:
        '200':
          description: sessionId
          sessionToken: null
          expiresAt: null
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/ai-intake:
    post:
      summary: Create or submit Ai Intake
      description: /ai-intake endpoint.
      tags:
        - Ai-Intake
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/ai/analyze:
    post:
      summary: Analyze image with AI
      description: >-
        Uses AI to analyze/tag an image (e.g. expense receipt). Body image
        (base64 or URL). Rate limited.
      tags:
        - AI
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                image:
                  type: string
                  description: Base64 or URL of image
      responses:
        '200':
          description: Analysis result (tags, labels, etc.)
        '400':
          description: Invalid image or missing image
        '401':
          description: Unauthorized
        '429':
          description: Rate limit exceeded
  /ai/cash-flow/forecast:
    post:
      summary: Generate cash flow forecast
      description: >-
        Generates cash flow forecast with scenario planning. Body timeframe (3,
        6, or 12 months), optional scenarios. Rate limited. Requires
        authentication.
      tags:
        - ai
        - financial
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - timeframe
              properties:
                timeframe:
                  type: integer
                  enum:
                    - 3
                    - 6
                    - 12
                  description: Months
                scenarios:
                  type: array
                  items:
                    type: object
      responses:
        '200':
          description: Forecast result
        '400':
          '6': null
          description: Timeframe must be 3
          or 12 months: null
        '401':
          description: Unauthorized
        '429':
          description: Rate limit exceeded
        '500':
          description: Internal server error
  /api/ai/categorize:
    post:
      summary: Categorize transaction with AI
      description: >-
        Uses AI to categorize a transaction. Body description, amount
        (required); type (expense/income) optional. Rate limited.
      tags:
        - AI
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - description
                - amount
              properties:
                description:
                  type: string
                amount:
                  type: number
                type:
                  type: string
                  enum:
                    - expense
                    - income
                  default: expense
      responses:
        '200':
          description: Categorization result (category, confidence, etc.)
        '400':
          description: Missing description or amount
        '401':
          description: Unauthorized
        '429':
          description: Rate limit exceeded
  /ai/chat/conversations/{id}:
    get:
      summary: Get conversation messages
      description: >-
        Returns messages for the given AI chat conversation. Requires
        authentication.
      tags:
        - ai
        - chat
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Conversation ID
      responses:
        '200':
          description: messages array
        '401':
          description: Unauthorized
        '404':
          description: Conversation not found
        '500':
          description: Internal server error
    delete:
      summary: Delete conversation
      description: >-
        Deletes an AI chat conversation and its messages. Requires
        authentication.
      tags:
        - ai
        - chat
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
        '401':
          description: Unauthorized
        '404':
          description: Conversation not found
        '500':
          description: Internal server error
  /ai/chat/conversations:
    get:
      summary: List AI chat conversations
      description: >-
        Returns the authenticated user AI chat conversations. Query param limit
        (default 20). Requires authentication.
      tags:
        - ai
        - chat
      parameters:
        - in: query
          name: limit
          schema:
            type: integer
            default: 20
      responses:
        '200':
          description: conversations array
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create AI chat conversation
      description: >-
        Creates a new AI chat conversation. Body may include title. Requires
        authentication.
      tags:
        - ai
        - chat
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                title:
                  type: string
      responses:
        '201':
          description: Created conversation
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /ai/chat/messages:
    post:
      summary: Send AI chat message
      description: >-
        Sends a message to an existing conversation. Body requires
        conversationId and message. Rate limited. Requires authentication.
      tags:
        - ai
        - chat
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - conversationId
                - message
              properties:
                conversationId:
                  type: string
                message:
                  type: string
      responses:
        '200':
          description: result object
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '429':
          description: Rate limit exceeded
        '500':
          description: Internal server error
  /ai/chat:
    post:
      summary: Send quick AI chat message
      description: >-
        Sends a single message and returns AI response. Rate limited. Requires
        userId and orgId. Body message (string). For full conversations use
        ai/chat/conversations and ai/chat/messages.
      tags:
        - ai
        - chat
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - message
              properties:
                message:
                  type: string
      responses:
        '200':
          description: AI result
        '400':
          description: Message is required
        '401':
          description: Unauthorized
        '429':
          description: Rate limit exceeded
        '500':
          description: Internal server error
  /api/ai/chat/suggestions:
    get:
      summary: Get conversation suggestions
      description: >-
        Returns AI-generated conversation starter suggestions for the
        authenticated user.
      tags:
        - AI
        - Chat
      responses:
        '200':
          description: List of suggestions
        '401':
          description: Unauthorized
  /ai/expenses/categorize:
    post:
      summary: Categorize expense with AI
      description: >-
        Categorize an expense using AI with tax deduction detection. Requires
        auth and rate limit.
      tags:
        - ai
        - expenses
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - description
                - amount
              properties:
                description:
                  type: string
                merchant:
                  type: string
                amount:
                  type: number
                date:
                  type: string
                  format: date-time
      responses:
        '200':
          description: Categorization result
        '400':
          description: Bad request (missing fields)
        '401':
          description: Unauthorized
        '429':
          description: Rate limited
        '500':
          description: Internal server error
  /api/ai/financbase-gpt:
    post:
      summary: Financbase GPT chat
      description: >-
        AI chat with financial context and analysis. Body messages (array),
        context (optional), analysisType (optional). Requires org. Rate limited.
      tags:
        - AI
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                messages:
                  type: array
                  items:
                    type: object
                context:
                  type: object
                analysisType:
                  type: string
      responses:
        '200':
          description: GPT response (message, analysis, etc.)
        '401':
          description: Unauthorized (userId or orgId required)
        '429':
          description: Rate limit exceeded
  /api/ai/financial-analysis:
    post:
      summary: AI-powered financial analysis
      description: >-
        Analyzes financial data using AI to provide insights, trends, and
        recommendations
      tags:
        - AI
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - revenue
                - expenses
                - budget
              properties:
                revenue:
                  type: number
                  example: 125000.5
                  description: Total revenue amount
                expenses:
                  type: number
                  example: 45000.25
                  description: Total expenses amount
                budget:
                  type: number
                  example: 150000
                  description: Budgeted amount
                transactions:
                  type: array
                  items:
                    type: object
                  description: Optional array of transaction details for deeper analysis
      responses:
        '200':
          description: Financial analysis completed successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      insights:
                        type: array
                        items:
                          type: string
                        example:
                          - Revenue increased 15% month-over-month
                          - Expenses are 8% under budget
                      recommendations:
                        type: array
                        items:
                          type: string
                      trends:
                        type: object
        '400':
          description: Bad request - Missing required fields
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /ai/invoices/generate:
    post:
      summary: Generate invoice with AI
      description: >-
        Generate an invoice using AI from natural language description. Requires
        auth and rate limit.
      tags:
        - ai
        - invoices
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - description
              properties:
                description:
                  type: string
                clientName:
                  type: string
                projectType:
                  type: string
                amount:
                  type: number
                items:
                  type: array
                dueDate:
                  type: string
                notes:
                  type: string
      responses:
        '200':
          description: Generated invoice
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '429':
          description: Rate limited
        '500':
          description: Internal server error
  /api/ai/tax-deductions:
    post:
      summary: Scan expenses for tax deductions
      description: >-
        Uses AI to scan expenses for potential tax deductions. Body expenses
        (array, required), businessType optional. Rate limited.
      tags:
        - AI
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - expenses
              properties:
                expenses:
                  type: array
                  items:
                    type: object
                    properties:
                      date:
                        type: string
                        format: date
                      description:
                        type: string
                      amount:
                        type: number
                businessType:
                  type: string
      responses:
        '200':
          description: Scan result with suggested deductions
        '400':
          description: Expenses array is required
        '401':
          description: Unauthorized
        '429':
          description: Rate limit exceeded
  /api/alerts/{id}/dismiss:
    put:
      summary: Update Dismiss
      description: /alerts/{id}/dismiss endpoint.
      tags:
        - Alerts
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/alerts/{id}/read:
    put:
      summary: Update Read
      description: /alerts/{id}/read endpoint.
      tags:
        - Alerts
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/alerts:
    get:
      summary: Get Alerts
      description: /alerts endpoint.
      tags:
        - Alerts
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Alerts
      description: /alerts endpoint.
      tags:
        - Alerts
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/alerts:
    post:
      summary: Create or submit Alerts
      description: /analytics/alerts endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/alerts/templates/{id}:
    get:
      summary: Get resource
      description: /analytics/alerts/templates/{id} endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /analytics/alerts/templates/{id} endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /analytics/alerts/templates/{id} endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/analytics/alerts/templates:
    get:
      summary: Get Templates
      description: /analytics/alerts/templates endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Templates
      description: /analytics/alerts/templates endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /analytics/clients:
    get:
      summary: Get client analytics
      description: >-
        Returns total clients, active clients, new clients this month,
        retention, and satisfaction score for the authenticated user.
      tags:
        - analytics
        - clients
      responses:
        '200':
          description: Client analytics object
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/analytics/cohorts/{cohortMonth}/health:
    get:
      summary: Get Health
      description: /analytics/cohorts/{cohortMonth}/health endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/analytics/cohorts/{cohortMonth}/retention-curve:
    get:
      summary: Get Retention Curve
      description: /analytics/cohorts/{cohortMonth}/retention-curve endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/analytics/cohorts/{cohortMonth}/revenue:
    get:
      summary: Get Revenue
      description: /analytics/cohorts/{cohortMonth}/revenue endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/analytics/cohorts/compare:
    post:
      summary: Create or submit Compare
      description: /analytics/cohorts/compare endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/cohorts/revenue:
    get:
      summary: Get Revenue
      description: /analytics/cohorts/revenue endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /analytics/cohorts:
    get:
      summary: Get cohort analysis
      description: >-
        Returns cohort analysis data. Query param monthsBack (default 12).
        Requires authentication.
      tags:
        - analytics
        - cohorts
      parameters:
        - in: query
          name: monthsBack
          schema:
            type: integer
            default: 12
      responses:
        '200':
          description: Cohort analysis data
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/analytics/conversion-metrics:
    get:
      summary: Get Conversion Metrics
      description: /analytics/conversion-metrics endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/custom-event:
    post:
      summary: Create or submit Custom Event
      description: /analytics/custom-event endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/error:
    post:
      summary: Create or submit Error
      description: /analytics/error endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /analytics/expenses:
    get:
      summary: Get expense analytics
      description: Returns expense analytics for the authenticated user.
      tags:
        - analytics
        - expenses
      responses:
        '200':
          description: Expense analytics object
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/analytics/interaction:
    post:
      summary: Create or submit Interaction
      description: /analytics/interaction endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/page-metrics:
    get:
      summary: Get Page Metrics
      description: /analytics/page-metrics endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Page Metrics
      description: /analytics/page-metrics endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /analytics/performance:
    get:
      summary: Get performance metrics
      description: Returns performance analytics metrics for the authenticated user.
      tags:
        - analytics
      responses:
        '200':
          description: Performance metrics object
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/analytics/realtime:
    get:
      summary: Get Realtime
      description: /analytics/realtime endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/revenue:
    get:
      summary: Get Revenue
      description: /analytics/revenue endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/route-change:
    post:
      summary: Create or submit Route Change
      description: /analytics/route-change endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics:
    get:
      summary: Get analytics and metrics
      description: >-
        Returns comprehensive financial analytics including revenue, expenses,
        net income, client counts, and growth metrics for the specified time
        period
      tags:
        - Analytics
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: period
          schema:
            type: string
            enum:
              - 7d
              - 30d
              - 90d
            default: 30d
          description: Time period for analytics (7 days, 30 days, or 90 days)
        - in: query
          name: metric
          schema:
            type: string
            default: overview
          description: Specific metric to retrieve (overview returns all metrics)
      responses:
        '200':
          description: Analytics data retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  revenue:
                    type: object
                    properties:
                      total:
                        type: number
                        example: 125000.5
                      growth:
                        type: number
                        example: 15.5
                  expenses:
                    type: object
                    properties:
                      total:
                        type: number
                        example: 45000.25
                      growth:
                        type: number
                        example: -5.2
                  netIncome:
                    type: number
                    example: 80000.25
                  clients:
                    type: object
                    properties:
                      total:
                        type: number
                        example: 45
                      active:
                        type: number
                        example: 38
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/analytics/segments/{id}/analytics:
    get:
      summary: Get Analytics
      description: /analytics/segments/{id}/analytics endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/analytics/segments/{id}:
    get:
      summary: Get resource
      description: /analytics/segments/{id} endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /analytics/segments/{id} endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /analytics/segments/{id} endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/analytics/segments/compare:
    post:
      summary: Create or submit Compare
      description: /analytics/segments/compare endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/segments:
    get:
      summary: Get Segments
      description: /analytics/segments endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Segments
      description: /analytics/segments endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/templates/{id}/clone:
    post:
      summary: Create or submit Clone
      description: /analytics/templates/{id}/clone endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/templates/{id}/rate:
    post:
      summary: Create or submit Rate
      description: /analytics/templates/{id}/rate endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/templates/{id}/ratings:
    get:
      summary: Get Ratings
      description: /analytics/templates/{id}/ratings endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/analytics/templates/{id}:
    get:
      summary: Get resource
      description: /analytics/templates/{id} endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /analytics/templates/{id} endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /analytics/templates/{id} endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/analytics/templates/{id}/share:
    post:
      summary: Create or submit Share
      description: /analytics/templates/{id}/share endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/templates/apply:
    post:
      summary: Create or submit Apply
      description: /analytics/templates/apply endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/templates/clear:
    post:
      summary: Create or submit Clear
      description: /analytics/templates/clear endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/templates/marketplace:
    get:
      summary: Get Marketplace
      description: /analytics/templates/marketplace endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/templates:
    get:
      summary: Get Templates
      description: /analytics/templates endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Templates
      description: /analytics/templates endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/upload:
    get:
      summary: Get Upload
      description: /analytics/upload endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/analytics/uploads:
    post:
      summary: Create or submit Uploads
      description: /analytics/uploads endpoint.
      tags:
        - Analytics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/approval-workflows:
    get:
      summary: Get list of approval workflows
      description: >-
        Retrieves a paginated list of bill approval workflows configured for the
        authenticated user
      tags:
        - Workflows
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: status
          schema:
            type: string
            enum:
              - active
              - inactive
          description: Filter workflows by status
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
          description: Maximum number of workflows to return
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
          description: Number of workflows to skip
      responses:
        '200':
          description: Approval workflows retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  workflows:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: workflow_123
                        name:
                          type: string
                          example: High Value Approval Workflow
                        description:
                          type: string
                        steps:
                          type: array
                          items:
                            type: object
                        status:
                          type: string
                          enum:
                            - active
                            - inactive
                  total:
                    type: integer
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Create a new approval workflow
      description: >-
        Creates a new bill approval workflow with configurable steps,
        thresholds, and conditions
      tags:
        - Workflows
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - steps
              properties:
                name:
                  type: string
                  example: High Value Approval Workflow
                description:
                  type: string
                  example: Multi-step approval for bills over $10,000
                amountThreshold:
                  type: number
                  example: 10000
                  description: Minimum bill amount to trigger this workflow
                vendorCategories:
                  type: array
                  items:
                    type: string
                  example:
                    - supplier
                    - contractor
                steps:
                  type: array
                  items:
                    type: object
                    properties:
                      approverId:
                        type: string
                      order:
                        type: integer
                      required:
                        type: boolean
                  description: Array of approval steps with approvers
      responses:
        '201':
          description: Approval workflow created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  workflow:
                    type: object
                    properties:
                      id:
                        type: string
                        example: workflow_123
                      name:
                        type: string
                      steps:
                        type: array
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/assets/{id}/depreciation:
    get:
      summary: Get Depreciation
      description: /assets/{id}/depreciation endpoint.
      tags:
        - Assets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/assets/{id}/maintenance:
    get:
      summary: Get Maintenance
      description: /assets/{id}/maintenance endpoint.
      tags:
        - Assets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Maintenance
      description: /assets/{id}/maintenance endpoint.
      tags:
        - Assets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/assets/{id}:
    get:
      summary: Get resource
      description: /assets/{id} endpoint.
      tags:
        - Assets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /assets/{id} endpoint.
      tags:
        - Assets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /assets/{id} endpoint.
      tags:
        - Assets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/assets:
    get:
      summary: Get Assets
      description: /assets endpoint.
      tags:
        - Assets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Assets
      description: /assets endpoint.
      tags:
        - Assets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/assets/summary:
    get:
      summary: Get Summary
      description: /assets/summary endpoint.
      tags:
        - Assets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/audio/upload:
    post:
      summary: Create or submit Upload
      description: /audio/upload endpoint.
      tags:
        - Audio
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/auth/admin-status:
    get:
      summary: Get Admin Status
      description: /auth/admin-status endpoint.
      tags:
        - Auth
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/auth/can-manage-ventures:
    get:
      summary: Check venture management permission
      description: >-
        Returns whether the current user can create or manage ventures
        (organizations). Only Financbase org members or platform-admins can
        manage ventures.
      tags:
        - Auth
      security:
        - BearerAuth: []
      responses:
        '200':
          description: Permission check result
          content:
            application/json:
              schema:
                type: object
                properties:
                  canManageVentures:
                    type: boolean
                    example: true
        '401':
          description: Unauthorized
  /api/auth/check-route-access:
    get:
      summary: Get Check Route Access
      description: /auth/check-route-access endpoint.
      tags:
        - Auth
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/auth/me:
    get:
      summary: Get Me
      description: /auth/me endpoint.
      tags:
        - Auth
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/auth/sync-metadata:
    post:
      summary: Create or submit Sync Metadata
      description: /auth/sync-metadata endpoint.
      tags:
        - Auth
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/auth/sync-user:
    get:
      summary: Get Sync User
      description: /auth/sync-user endpoint.
      tags:
        - Auth
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Sync User
      description: /auth/sync-user endpoint.
      tags:
        - Auth
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/auth/user:
    get:
      summary: Get current authenticated user information
      description: >-
        Returns detailed information about the currently authenticated user from
        Clerk
      tags:
        - Authentication
      security:
        - BearerAuth: []
      responses:
        '200':
          description: User information retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    example: user_123
                  email:
                    type: string
                    format: email
                    example: user@example.com
                  firstName:
                    type: string
                    example: John
                  lastName:
                    type: string
                    example: Doe
                  username:
                    type: string
                    example: johndoe
                  imageUrl:
                    type: string
                    format: uri
                    example: https://img.clerk.com/...
                  createdAt:
                    type: integer
                    format: int64
                    example: 1704067200000
                  updatedAt:
                    type: integer
                    format: int64
                  emailVerified:
                    type: boolean
                    example: true
                  phoneVerified:
                    type: boolean
                    example: false
                  hasImage:
                    type: boolean
                    example: true
                  primaryEmail:
                    type: string
                    format: email
                  primaryPhone:
                    type: string
        '401':
          description: Unauthorized - Authentication required
        '404':
          description: User not found
        '500':
          description: Internal server error
  /api/auth/validate-token:
    post:
      summary: Validate Clerk JWT token for WebSocket connections
      description: >-
        Validates a Clerk JWT token and returns user information. Used by
        Cloudflare Workers to authenticate WebSocket connections.
      tags:
        - Authentication
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - token
              properties:
                token:
                  type: string
                  description: Clerk session token obtained from getToken()
      responses:
        '200':
          description: Token is valid
          content:
            application/json:
              schema:
                type: object
                properties:
                  valid:
                    type: boolean
                    example: true
                  userId:
                    type: string
                    example: user_123
                  email:
                    type: string
                    example: user@example.com
        '400':
          description: Token is required
        '401':
          description: Token is invalid, expired, or user account is inactive
    get:
      summary: Health check for token validation endpoint
      description: Returns the status of the token validation endpoint
      tags:
        - Authentication
      responses:
        '200':
          description: Endpoint is active
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: ok
                  message:
                    type: string
                    example: Token validation endpoint is active
  /api/authors/{id}:
    get:
      summary: Get resource
      description: /authors/{id} endpoint.
      tags:
        - Authors
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /authors/{id} endpoint.
      tags:
        - Authors
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /authors/{id} endpoint.
      tags:
        - Authors
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/authors:
    get:
      summary: Get Authors
      description: /authors endpoint.
      tags:
        - Authors
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Authors
      description: /authors endpoint.
      tags:
        - Authors
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/automations/templates:
    get:
      summary: Get Templates
      description: /automations/templates endpoint.
      tags:
        - Automations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Templates
      description: /automations/templates endpoint.
      tags:
        - Automations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/banking/pr-connect:
    post:
      summary: Create or submit Pr Connect
      description: /banking/pr-connect endpoint.
      tags:
        - Banking
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/bills/attention:
    get:
      summary: Get Attention
      description: /bills/attention endpoint.
      tags:
        - Bills
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/bills/process:
    get:
      summary: Get Process
      description: /bills/process endpoint.
      tags:
        - Bills
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Process
      description: /bills/process endpoint.
      tags:
        - Bills
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/bills:
    get:
      summary: Get list of bills
      description: >-
        Retrieves a paginated list of bills with optional filtering by status
        and vendor
      tags:
        - Financial
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: status
          schema:
            type: string
            enum:
              - draft
              - received
              - processing
              - pending_approval
              - approved
              - rejected
              - paid
              - overdue
              - cancelled
              - disputed
          description: Filter bills by status
        - in: query
          name: vendorId
          schema:
            type: string
          description: Filter bills by vendor ID
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
          description: Maximum number of bills to return
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
          description: Number of bills to skip
      responses:
        '200':
          description: Bills retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  bills:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: bill_123
                        vendorId:
                          type: string
                        amount:
                          type: number
                          example: 1250
                        currency:
                          type: string
                          example: USD
                        status:
                          type: string
                          enum:
                            - draft
                            - received
                            - processing
                            - pending_approval
                            - approved
                            - rejected
                            - paid
                            - overdue
                            - cancelled
                            - disputed
                        dueDate:
                          type: string
                          format: date-time
                        invoiceNumber:
                          type: string
                          example: INV-2025-001
                  total:
                    type: integer
                    example: 125
                  limit:
                    type: integer
                  offset:
                    type: integer
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Create a new bill
      description: >-
        Creates a new bill record for processing, OCR extraction, and payment
        automation
      tags:
        - Financial
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - vendorId
                - amount
                - invoiceNumber
              properties:
                vendorId:
                  type: string
                  example: vendor_123
                amount:
                  type: number
                  example: 1250
                currency:
                  type: string
                  default: USD
                dueDate:
                  type: string
                  format: date-time
                issueDate:
                  type: string
                  format: date-time
                invoiceNumber:
                  type: string
                  example: INV-2025-001
                description:
                  type: string
                category:
                  type: string
                documentUrl:
                  type: string
                  format: uri
                status:
                  type: string
                  enum:
                    - draft
                    - received
                    - processing
                    - pending_approval
                    - approved
                    - rejected
                    - paid
                    - overdue
                    - cancelled
                    - disputed
                  default: received
      responses:
        '201':
          description: Bill created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  bill:
                    type: object
                    properties:
                      id:
                        type: string
                        example: bill_123
                      invoiceNumber:
                        type: string
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/blog/{id}/like:
    post:
      summary: Create or submit Like
      description: /blog/{id}/like endpoint.
      tags:
        - Blog
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/blog/{id}/publish:
    post:
      summary: Create or submit Publish
      description: /blog/{id}/publish endpoint.
      tags:
        - Blog
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/blog/{id}:
    get:
      summary: Get resource
      description: /blog/{id} endpoint.
      tags:
        - Blog
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /blog/{id} endpoint.
      tags:
        - Blog
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /blog/{id} endpoint.
      tags:
        - Blog
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/blog/categories:
    get:
      summary: Get Categories
      description: /blog/categories endpoint.
      tags:
        - Blog
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Categories
      description: /blog/categories endpoint.
      tags:
        - Blog
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/blog:
    get:
      summary: Get Blog
      description: /blog endpoint.
      tags:
        - Blog
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Blog
      description: /blog endpoint.
      tags:
        - Blog
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/blog/stats:
    get:
      summary: Get Stats
      description: /blog/stats endpoint.
      tags:
        - Blog
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/budgets/{id}:
    get:
      summary: Get budget by ID
      description: Returns a single budget with spending details. User must own the budget.
      tags:
        - Budgets
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Budget ID
      responses:
        '200':
          description: Budget with spending details
        '400':
          description: Invalid budget ID
        '401':
          description: Unauthorized
        '404':
          description: Budget not found
    patch:
      summary: Update budget
      description: Updates a budget. Body validated by updateBudgetSchema.
      tags:
        - Budgets
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Budget ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
      responses:
        '200':
          description: Updated budget
        '400':
          description: Invalid budget ID or validation error
        '401':
          description: Unauthorized
        '404':
          description: Budget not found
    delete:
      summary: Delete budget
      description: Deletes a budget. User must own the budget.
      tags:
        - Budgets
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Budget ID
      responses:
        '200':
          description: Budget deleted
        '400':
          description: Invalid budget ID
        '401':
          description: Unauthorized
        '404':
          description: Budget not found
  /api/budgets/alerts:
    get:
      summary: Get Alerts
      description: /budgets/alerts endpoint.
      tags:
        - Budgets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/budgets/categories/{id}:
    get:
      summary: Get resource
      description: /budgets/categories/{id} endpoint.
      tags:
        - Budgets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /budgets/categories/{id} endpoint.
      tags:
        - Budgets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/budgets/categories:
    get:
      summary: Get Categories
      description: /budgets/categories endpoint.
      tags:
        - Budgets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Categories
      description: /budgets/categories endpoint.
      tags:
        - Budgets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/budgets:
    get:
      summary: Get list of budgets
      description: >-
        Retrieves a paginated list of budgets with optional filtering by
        category, status, and period type
      tags:
        - Financial
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: category
          schema:
            type: string
          description: Filter budgets by category
        - in: query
          name: status
          schema:
            type: string
            enum:
              - active
              - archived
              - paused
          description: Filter budgets by status
        - in: query
          name: periodType
          schema:
            type: string
            enum:
              - monthly
              - yearly
          description: Filter budgets by period type
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
          description: Maximum number of budgets to return
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
          description: Number of budgets to skip
      responses:
        '200':
          description: Budgets retrieved successfully
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Create a new budget
      description: Creates a new budget record for the authenticated user
      tags:
        - Financial
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - category
                - budgetedAmount
                - periodType
                - startDate
                - endDate
              properties:
                name:
                  type: string
                  example: Marketing Q1 2025
                category:
                  type: string
                  example: Marketing
                budgetedAmount:
                  type: number
                  example: 15000
                periodType:
                  type: string
                  enum:
                    - monthly
                    - yearly
                  example: monthly
                startDate:
                  type: string
                  format: date-time
                endDate:
                  type: string
                  format: date-time
      responses:
        '201':
          description: Budget created successfully
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/budgets/summary:
    get:
      summary: Get budget summary
      description: >-
        Returns overall budget statistics and summary for the authenticated
        user.
      tags:
        - Budgets
      responses:
        '200':
          description: Budget summary (success, data with statistics)
        '401':
          description: Unauthorized
  /api/byok/api-keys/{keyId}:
    put:
      summary: Update resource
      description: /byok/api-keys/{keyId} endpoint.
      tags:
        - Byok
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /byok/api-keys/{keyId} endpoint.
      tags:
        - Byok
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/byok/api-keys:
    get:
      summary: Get Api Keys
      description: /byok/api-keys endpoint.
      tags:
        - Byok
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Api Keys
      description: /byok/api-keys endpoint.
      tags:
        - Byok
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/byok/preferences:
    get:
      summary: Get Preferences
      description: /byok/preferences endpoint.
      tags:
        - Byok
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    put:
      summary: Update Preferences
      description: /byok/preferences endpoint.
      tags:
        - Byok
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/byok/providers:
    get:
      summary: Get Providers
      description: /byok/providers endpoint.
      tags:
        - Byok
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Providers
      description: /byok/providers endpoint.
      tags:
        - Byok
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/byok/usage:
    get:
      summary: Get Usage
      description: /byok/usage endpoint.
      tags:
        - Byok
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Usage
      description: /byok/usage endpoint.
      tags:
        - Byok
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/calendar/events/{id}:
    get:
      summary: Get resource
      description: /calendar/events/{id} endpoint.
      tags:
        - Calendar
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /calendar/events/{id} endpoint.
      tags:
        - Calendar
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /calendar/events/{id} endpoint.
      tags:
        - Calendar
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/calendar/events:
    get:
      summary: Get Events
      description: /calendar/events endpoint.
      tags:
        - Calendar
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Events
      description: /calendar/events endpoint.
      tags:
        - Calendar
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/campaigns/{id}/pause:
    post:
      summary: Create or submit Pause
      description: /campaigns/{id}/pause endpoint.
      tags:
        - Campaigns
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/campaigns/{id}/resume:
    post:
      summary: Create or submit Resume
      description: /campaigns/{id}/resume endpoint.
      tags:
        - Campaigns
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/campaigns/{id}:
    get:
      summary: Get resource
      description: /campaigns/{id} endpoint.
      tags:
        - Campaigns
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /campaigns/{id} endpoint.
      tags:
        - Campaigns
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /campaigns/{id} endpoint.
      tags:
        - Campaigns
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /campaigns/performance:
    get:
      summary: Get campaign performance metrics
      description: >-
        Returns performance metrics for the authenticated user's campaigns
        within the given date range. Requires startDate and endDate.
      tags:
        - campaigns
        - performance
      parameters:
        - in: query
          name: startDate
          required: true
          schema:
            type: string
            format: date
          description: Start date (ISO or YYYY-MM-DD).
        - in: query
          name: endDate
          required: true
          schema:
            type: string
            format: date
          description: End date (ISO or YYYY-MM-DD).
      responses:
        '200':
          description: Performance metrics object
        '400':
          description: Missing or invalid startDate/endDate
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/campaigns:
    get:
      summary: Get Campaigns
      description: /campaigns endpoint.
      tags:
        - Campaigns
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Campaigns
      description: /campaigns endpoint.
      tags:
        - Campaigns
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/campaigns/stats:
    get:
      summary: Get Stats
      description: /campaigns/stats endpoint.
      tags:
        - Campaigns
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/careers/{id}:
    get:
      summary: Get resource
      description: /careers/{id} endpoint.
      tags:
        - Careers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/careers:
    get:
      summary: Get Careers
      description: /careers endpoint.
      tags:
        - Careers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /cart/abandoned:
    post:
      summary: Report cart abandonment
      description: >-
        Records cart abandonment and triggers cart.abandoned workflow (e.g.
        marketing, n8n). Body optional email, cartItems, createdAt. Auth
        optional (userId if signed in). Call from client on beforeunload or
        after idle.
      tags:
        - cart
        - webhooks
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                email:
                  type: string
                cartItems:
                  type: array
                  items:
                    type: object
                createdAt:
                  type: number
      responses:
        '200':
          description: Workflow triggers checked
        '500':
          description: Internal server error
  /api/chat/calls:
    post:
      summary: Create or submit Calls
      description: /chat/calls endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat/channels/{id}/messages:
    get:
      summary: Get Messages
      description: /chat/channels/{id}/messages endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Messages
      description: /chat/channels/{id}/messages endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat/channels/{id}:
    get:
      summary: Get resource
      description: /chat/channels/{id} endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /chat/channels/{id} endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/chat/channels:
    get:
      summary: Get Channels
      description: /chat/channels endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Channels
      description: /chat/channels endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat/meetings:
    post:
      summary: Create or submit Meetings
      description: /chat/meetings endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat/messages/{id}/read:
    post:
      summary: Create or submit Read
      description: /chat/messages/{id}/read endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat/messages/{id}:
    patch:
      summary: Update resource
      description: /chat/messages/{id} endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /chat/messages/{id} endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/chat/messages:
    get:
      summary: Get Messages
      description: /chat/messages endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Messages
      description: /chat/messages endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat/public/ai:
    post:
      summary: Create or submit Ai
      description: /chat/public/ai endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat/public/messages:
    get:
      summary: Get Messages
      description: /chat/public/messages endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Messages
      description: /chat/public/messages endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat/public:
    post:
      summary: Create or submit Public
      description: /chat/public endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat/public/status:
    get:
      summary: Get Status
      description: /chat/public/status endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat:
    get:
      summary: Get Chat
      description: /chat endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat/search:
    get:
      summary: Get Search
      description: /chat/search endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/chat/status:
    get:
      summary: Get Status
      description: /chat/status endpoint.
      tags:
        - Chat
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/checkout/create-session:
    post:
      summary: Create or submit Create Session
      description: /checkout/create-session endpoint.
      tags:
        - Checkout
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /clients/{id}:
    get:
      summary: Get client by ID
      description: Returns a single client by ID for the authenticated user.
      tags:
        - clients
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Client ID
      responses:
        '200':
          description: Client object in body.client
        '401':
          description: Unauthorized
        '404':
          description: Client not found
        '500':
          description: Internal server error
    put:
      summary: Update client
      description: >-
        Updates an existing client. Accepts companyName, contactName, email,
        phone, address, etc.
      tags:
        - clients
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Client ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                companyName:
                  type: string
                contactName:
                  type: string
                email:
                  type: string
                phone:
                  type: string
                address:
                  type: string
                isActive:
                  type: boolean
      responses:
        '200':
          description: Updated client in body.client
        '400':
          description: Invalid JSON or invalid client ID
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    delete:
      summary: Delete client
      description: Deletes a client for the authenticated user.
      tags:
        - clients
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Client ID
      responses:
        '200':
          description: Success
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /clients:
    get:
      summary: List clients
      description: Returns all clients for the authenticated user's active organization.
      tags:
        - clients
      responses:
        '200':
          description: List of clients in body.clients
        '400':
          description: Organization ID required
        '404':
          description: User not found
        '500':
          description: Internal server error
    post:
      summary: Create client
      description: >-
        Creates a new client. Requires name; optional email, phone, company,
        address, notes.
      tags:
        - clients
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - name
              properties:
                name:
                  type: string
                email:
                  type: string
                phone:
                  type: string
                company:
                  type: string
                address:
                  type: string
                notes:
                  type: string
      responses:
        '201':
          description: Created client in body.client
        '400':
          description: Organization ID required or validation error
        '404':
          description: User not found
        '500':
          description: Internal server error
  /api/clients/stats:
    get:
      summary: Get Stats
      description: /clients/stats endpoint.
      tags:
        - Clients
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/address/verify:
    post:
      summary: Create or submit Verify
      description: /compliance/address/verify endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/ai-governance/bias-checks/{id}:
    get:
      summary: Get resource
      description: /compliance/ai-governance/bias-checks/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/ai-governance/bias-checks:
    get:
      summary: Get Bias Checks
      description: /compliance/ai-governance/bias-checks endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Bias Checks
      description: /compliance/ai-governance/bias-checks endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/ai-governance/decisions/{id}:
    get:
      summary: Get resource
      description: /compliance/ai-governance/decisions/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/ai-governance/decisions:
    get:
      summary: Get Decisions
      description: /compliance/ai-governance/decisions endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Decisions
      description: /compliance/ai-governance/decisions endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/audits:
    get:
      summary: Get Audits
      description: /compliance/audits endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Audits
      description: /compliance/audits endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/baa/vendors:
    get:
      summary: Get Vendors
      description: /compliance/baa/vendors endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Vendors
      description: /compliance/baa/vendors endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/data-classification/bulk:
    post:
      summary: Create or submit Bulk
      description: /compliance/data-classification/bulk endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/data-classification:
    get:
      summary: Get Data Classification
      description: /compliance/data-classification endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Data Classification
      description: /compliance/data-classification endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/dora/incidents/{id}:
    get:
      summary: Get resource
      description: /compliance/dora/incidents/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /compliance/dora/incidents/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/dora/incidents:
    get:
      summary: Get Incidents
      description: /compliance/dora/incidents endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Incidents
      description: /compliance/dora/incidents endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/dora/resilience-tests/{id}:
    get:
      summary: Get resource
      description: /compliance/dora/resilience-tests/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /compliance/dora/resilience-tests/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/dora/resilience-tests:
    get:
      summary: Get Resilience Tests
      description: /compliance/dora/resilience-tests endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Resilience Tests
      description: /compliance/dora/resilience-tests endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/dora/third-party-risks/{id}:
    get:
      summary: Get resource
      description: /compliance/dora/third-party-risks/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /compliance/dora/third-party-risks/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/dora/third-party-risks:
    get:
      summary: Get Third Party Risks
      description: /compliance/dora/third-party-risks endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Third Party Risks
      description: /compliance/dora/third-party-risks endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/employment-tax/validate:
    get:
      summary: Get Validate
      description: /compliance/employment-tax/validate endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Validate
      description: /compliance/employment-tax/validate endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/gdpr/data-subject-requests/{id}/fulfill:
    post:
      summary: Create or submit Fulfill
      description: /compliance/gdpr/data-subject-requests/{id}/fulfill endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/gdpr/data-subject-requests/{id}:
    get:
      summary: Get resource
      description: /compliance/gdpr/data-subject-requests/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /compliance/gdpr/data-subject-requests/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/gdpr/data-subject-requests:
    get:
      summary: Get Data Subject Requests
      description: /compliance/gdpr/data-subject-requests endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Data Subject Requests
      description: /compliance/gdpr/data-subject-requests endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/incident-response/communication-templates:
    get:
      summary: Get Communication Templates
      description: /compliance/incident-response/communication-templates endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Communication Templates
      description: /compliance/incident-response/communication-templates endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/incident-response/drills/{id}:
    patch:
      summary: Update resource
      description: /compliance/incident-response/drills/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/incident-response/drills:
    get:
      summary: Get Drills
      description: /compliance/incident-response/drills endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Drills
      description: /compliance/incident-response/drills endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/incident-response/incidents/{id}:
    get:
      summary: Get resource
      description: /compliance/incident-response/incidents/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /compliance/incident-response/incidents/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/incident-response/incidents:
    get:
      summary: Get Incidents
      description: /compliance/incident-response/incidents endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Incidents
      description: /compliance/incident-response/incidents endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/incident-response/runbooks:
    get:
      summary: Get Runbooks
      description: /compliance/incident-response/runbooks endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Runbooks
      description: /compliance/incident-response/runbooks endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/incident-response/team:
    get:
      summary: Get Team
      description: /compliance/incident-response/team endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Team
      description: /compliance/incident-response/team endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /compliance/logs/archived:
    get:
      summary: Get archived compliance logs
      description: >-
        Retrieves archived logs from cloud storage for compliance. Admin or
        compliance_manager role required. Query params may include startDate,
        endDate, limit. Requires authentication.
      tags:
        - compliance
      parameters:
        - in: query
          name: startDate
          schema:
            type: string
            format: date
        - in: query
          name: endDate
          schema:
            type: string
            format: date
        - in: query
          name: limit
          schema:
            type: integer
      responses:
        '200':
          description: Archived logs or download URL
        '400':
          description: Organization ID required
        '401':
          description: Unauthorized
        '403':
          description: Forbidden - Admin or compliance manager required
        '500':
          description: Internal server error
  /api/compliance/monitoring/alerts/{id}:
    patch:
      summary: Update resource
      description: /compliance/monitoring/alerts/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/monitoring/alerts:
    get:
      summary: Get Alerts
      description: /compliance/monitoring/alerts endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/monitoring/alerts/rules:
    post:
      summary: Create or submit Rules
      description: /compliance/monitoring/alerts/rules endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/monitoring:
    get:
      summary: Get Monitoring
      description: /compliance/monitoring endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/monitoring/siem/events:
    get:
      summary: Get Events
      description: /compliance/monitoring/siem/events endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Events
      description: /compliance/monitoring/siem/events endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/monitoring/siem/integrations:
    get:
      summary: Get Integrations
      description: /compliance/monitoring/siem/integrations endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Integrations
      description: /compliance/monitoring/siem/integrations endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/nexus/determine:
    get:
      summary: Get Determine
      description: /compliance/nexus/determine endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Determine
      description: /compliance/nexus/determine endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/policies/{id}/assignments:
    get:
      summary: Get Assignments
      description: /compliance/policies/{id}/assignments endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Assignments
      description: /compliance/policies/{id}/assignments endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/policies/{id}:
    get:
      summary: Get resource
      description: /compliance/policies/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /compliance/policies/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/policies/{id}/versions:
    get:
      summary: Get Versions
      description: /compliance/policies/{id}/versions endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/policies/create-from-template:
    post:
      summary: Create or submit Create From Template
      description: /compliance/policies/create-from-template endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/policies:
    get:
      summary: Get Policies
      description: /compliance/policies endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Policies
      description: /compliance/policies endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/policies/templates:
    get:
      summary: Get Templates
      description: /compliance/policies/templates endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /compliance/reports/{id}/export:
    post:
      summary: Export compliance report
      description: >-
        Exports a compliance report in the requested format (pdf, csv, json).
        Body format defaults to pdf.
      tags:
        - compliance
        - reports
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
          description: Report ID.
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                format:
                  type: string
                  enum:
                    - pdf
                    - csv
                    - json
                  default: pdf
      responses:
        '200':
          description: File content (Content-Type and Content-Disposition set)
        '400':
          description: Invalid JSON
        '401':
          description: Unauthorized
        '404':
          description: Report not found
        '500':
          description: Internal server error
  /compliance/reports/{id}:
    get:
      summary: Get compliance report by ID
      description: >-
        Returns a single compliance report by ID. Report must belong to the
        authenticated organization.
      tags:
        - compliance
        - reports
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
          description: Report ID.
      responses:
        '200':
          description: Report in data
        '400':
          description: Invalid report ID
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Report not found
        '500':
          description: Internal server error
  /compliance/reports/dashboard:
    get:
      summary: Compliance reports dashboard
      description: >-
        Returns compliance dashboard data for the organization (recent reports,
        resilience metrics, AI governance, state privacy, data classification,
        incidents, AI decisions).
      tags:
        - compliance
        - reports
      responses:
        '200':
          description: Dashboard object
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /compliance/reports:
    get:
      summary: List compliance reports
      description: >-
        Returns compliance reports for the authenticated organization. Optional
        reportType, limit, offset.
      tags:
        - compliance
        - reports
      parameters:
        - in: query
          name: reportType
          schema:
            type: string
          description: Filter by report type.
        - in: query
          name: limit
          schema:
            type: integer
            default: 100
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: List of reports in data
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create compliance report
      description: >-
        Generates a compliance report (gdpr, soc2, etc.). Body requires
        reportType; optional filters.
      tags:
        - compliance
        - reports
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - reportType
              properties:
                reportType:
                  type: string
                filters:
                  type: object
      responses:
        '200':
          description: Report created
        '400':
          description: Missing reportType
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/compliance/risk-assessment/assets:
    get:
      summary: Get Assets
      description: /compliance/risk-assessment/assets endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Assets
      description: /compliance/risk-assessment/assets endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/risk-assessment/risks:
    get:
      summary: Get Risks
      description: /compliance/risk-assessment/risks endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Risks
      description: /compliance/risk-assessment/risks endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/risk-assessment/summary:
    get:
      summary: Get Summary
      description: /compliance/risk-assessment/summary endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/risk-assessment/threats:
    get:
      summary: Get Threats
      description: /compliance/risk-assessment/threats endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Threats
      description: /compliance/risk-assessment/threats endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/risk-assessment/vulnerabilities:
    get:
      summary: Get Vulnerabilities
      description: /compliance/risk-assessment/vulnerabilities endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Vulnerabilities
      description: /compliance/risk-assessment/vulnerabilities endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/sales-tax/{state}:
    get:
      summary: Get resource
      description: /compliance/sales-tax/{state} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/sales-tax/summary:
    get:
      summary: Get Summary
      description: /compliance/sales-tax/summary endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/sales-tax/validate:
    get:
      summary: Get Validate
      description: /compliance/sales-tax/validate endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Validate
      description: /compliance/sales-tax/validate endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/state-revenue/{state}:
    get:
      summary: Get resource
      description: /compliance/state-revenue/{state} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/state-revenue:
    get:
      summary: Get State Revenue
      description: /compliance/state-revenue endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/state-tax/validate:
    get:
      summary: Get Validate
      description: /compliance/state-tax/validate endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Validate
      description: /compliance/state-tax/validate endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/tasks/{id}:
    get:
      summary: Get resource
      description: /compliance/tasks/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /compliance/tasks/{id} endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/compliance/tasks:
    get:
      summary: Get Tasks
      description: /compliance/tasks endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Tasks
      description: /compliance/tasks endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/tax-deposits/balance-due:
    get:
      summary: Get Balance Due
      description: /compliance/tax-deposits/balance-due endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/tax-deposits:
    get:
      summary: Get Tax Deposits
      description: /compliance/tax-deposits endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Tax Deposits
      description: /compliance/tax-deposits endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/training/assignments:
    get:
      summary: Get Assignments
      description: /compliance/training/assignments endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Assignments
      description: /compliance/training/assignments endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/training/programs:
    post:
      summary: Create or submit Programs
      description: /compliance/training/programs endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/w9/pending:
    get:
      summary: Get Pending
      description: /compliance/w9/pending endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/w9/reminder:
    post:
      summary: Create or submit Reminder
      description: /compliance/w9/reminder endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/w9/request:
    post:
      summary: Create or submit Request
      description: /compliance/w9/request endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/w9/submit:
    post:
      summary: Create or submit Submit
      description: /compliance/w9/submit endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/compliance/w9/verify:
    get:
      summary: Get Verify
      description: /compliance/w9/verify endpoint.
      tags:
        - Compliance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/contact:
    post:
      summary: Create or submit Contact
      description: /contact endpoint.
      tags:
        - Contact
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/content/pages:
    get:
      summary: Get Pages
      description: /content/pages endpoint.
      tags:
        - Content
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Pages
      description: /content/pages endpoint.
      tags:
        - Content
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/cookies/accept-all:
    post:
      summary: Create or submit Accept All
      description: /cookies/accept-all endpoint.
      tags:
        - Cookies
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/cookies/preferences:
    get:
      summary: Get Preferences
      description: /cookies/preferences endpoint.
      tags:
        - Cookies
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Preferences
      description: /cookies/preferences endpoint.
      tags:
        - Cookies
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/cookies/reject-all:
    post:
      summary: Create or submit Reject All
      description: /cookies/reject-all endpoint.
      tags:
        - Cookies
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/cron/account-sync:
    get:
      summary: Get Account Sync
      description: /cron/account-sync endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Account Sync
      description: /cron/account-sync endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/cron/api-key-notifications:
    get:
      summary: Get Api Key Notifications
      description: /cron/api-key-notifications endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Api Key Notifications
      description: /cron/api-key-notifications endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/cron/archive-logs:
    get:
      summary: Get Archive Logs
      description: /cron/archive-logs endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Archive Logs
      description: /cron/archive-logs endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /cron/execute-scheduled-workflows:
    post:
      summary: Execute scheduled workflows (cron)
      description: >-
        Cron job to check and execute scheduled workflows. Secured by
        x-cron-secret header. Run every 15-30 min.
      tags:
        - cron
      parameters:
        - in: header
          name: x-cron-secret
          schema:
            type: string
      responses:
        '200':
          description: Result with executed/errors/checked counts
        '401':
          description: Unauthorized (invalid cron secret)
        '500':
          description: Internal server error
  /cron/invoice-overdue:
    post:
      summary: Invoice overdue cron job
      description: >-
        Finds invoices past due (sent/viewed, dueDate < now), marks them
        overdue, and emits invoice.overdue workflow events. Secured by
        x-cron-secret header. Run daily (e.g. 9am).
      tags:
        - cron
        - billing
      parameters:
        - in: header
          name: x-cron-secret
          schema:
            type: string
          description: CRON_SECRET env value for authorization
      responses:
        '200':
          description: Overdue count and processed IDs
        '401':
          description: Unauthorized (missing or invalid x-cron-secret)
        '500':
          description: Internal server error
  /api/cron/market-tracking:
    get:
      summary: Get Market Tracking
      description: /cron/market-tracking endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Market Tracking
      description: /cron/market-tracking endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/cron/process-notification-queue:
    get:
      summary: Get Process Notification Queue
      description: /cron/process-notification-queue endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Process Notification Queue
      description: /cron/process-notification-queue endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/cron/retry-webhook-events:
    post:
      summary: Create or submit Retry Webhook Events
      description: /cron/retry-webhook-events endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/cron/rotate-api-keys:
    get:
      summary: Get Rotate Api Keys
      description: /cron/rotate-api-keys endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Rotate Api Keys
      description: /cron/rotate-api-keys endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/cron/subscription-grace-period:
    get:
      summary: Get Subscription Grace Period
      description: /cron/subscription-grace-period endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Subscription Grace Period
      description: /cron/subscription-grace-period endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/cron/upgrade-emails:
    get:
      summary: Get Upgrade Emails
      description: /cron/upgrade-emails endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Upgrade Emails
      description: /cron/upgrade-emails endpoint.
      tags:
        - Cron
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /cron/user-inactive:
    post:
      summary: User inactive cron job
      description: >-
        Finds users with no workflow execution in the last N days
        (INACTIVE_USER_DAYS env, default 30) and triggers user.inactive workflow
        automations. Secured by x-cron-secret. Run daily (e.g. 2am).
      tags:
        - cron
      parameters:
        - in: header
          name: x-cron-secret
          schema:
            type: string
          description: CRON_SECRET env value for authorization
      responses:
        '200':
          description: Inactive count and processed user IDs
        '401':
          description: Unauthorized (missing or invalid x-cron-secret)
        '500':
          description: Internal server error
  /api/customers/{id}:
    get:
      summary: Get resource
      description: /customers/{id} endpoint.
      tags:
        - Customers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /customers/{id} endpoint.
      tags:
        - Customers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /customers/{id} endpoint.
      tags:
        - Customers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /customers/analytics:
    get:
      summary: Get customer analytics
      description: >-
        Returns customer analytics for the authenticated user (from
        CustomersService).
      tags:
        - customers
        - analytics
      responses:
        '200':
          description: Customer analytics object
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/customers:
    get:
      summary: Get Customers
      description: /customers endpoint.
      tags:
        - Customers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Customers
      description: /customers endpoint.
      tags:
        - Customers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/customers/segments/{id}:
    get:
      summary: Get resource
      description: /customers/segments/{id} endpoint.
      tags:
        - Customers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /customers/segments/{id} endpoint.
      tags:
        - Customers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /customers/segments/{id} endpoint.
      tags:
        - Customers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/customers/segments:
    get:
      summary: Get Segments
      description: /customers/segments endpoint.
      tags:
        - Customers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Segments
      description: /customers/segments endpoint.
      tags:
        - Customers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/dashboard/ai-insights:
    get:
      summary: Get AI-powered financial insights
      description: >-
        Returns AI-generated insights and recommendations based on financial
        data analysis including revenue trends, expense patterns, and health
        scores
      tags:
        - Dashboard
        - AI
      security:
        - BearerAuth: []
      responses:
        '200':
          description: AI insights retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  insights:
                    type: array
                    items:
                      type: string
                    example:
                      - Revenue has increased 15% month-over-month
                      - Expenses are 8% under budget
                  recommendations:
                    type: array
                    items:
                      type: string
                  healthScore:
                    type: number
                    minimum: 0
                    maximum: 100
                    example: 85
                  trends:
                    type: object
                    properties:
                      revenue:
                        type: string
                        enum:
                          - increasing
                          - stable
                          - decreasing
                      expenses:
                        type: string
                        enum:
                          - increasing
                          - stable
                          - decreasing
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/dashboard/chart-data:
    get:
      summary: Get Chart Data
      description: /dashboard/chart-data endpoint.
      tags:
        - Dashboard
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/dashboard/executive-metrics:
    get:
      summary: Get Executive Metrics
      description: /dashboard/executive-metrics endpoint.
      tags:
        - Dashboard
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/dashboard/export:
    get:
      summary: Export dashboard data as CSV
      description: Exports dashboard overview metrics and recent activity as a CSV file
      tags:
        - Dashboard
      security:
        - BearerAuth: []
      responses:
        '200':
          description: CSV file with dashboard data
          content:
            text/csv:
              schema:
                type: string
                format: binary
          headers:
            Content-Disposition:
              schema:
                type: string
                example: attachment; filename="dashboard-export-2025-01-XX.csv"
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/dashboard/overview:
    get:
      summary: Get dashboard overview metrics
      description: >-
        Returns comprehensive dashboard overview data including revenue,
        expenses, clients, invoices, and net income metrics
      tags:
        - Dashboard
      security:
        - BearerAuth: []
      responses:
        '200':
          description: Dashboard overview data retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                    example: Dashboard API with real database data works!
                  overview:
                    type: object
                    description: Dashboard metrics and statistics
                    properties:
                      totalRevenue:
                        type: number
                        example: 125000.5
                      totalExpenses:
                        type: number
                        example: 45000.25
                      netIncome:
                        type: number
                        example: 80000.25
                      totalClients:
                        type: number
                        example: 45
                      activeProjects:
                        type: number
                        example: 12
                  userId:
                    type: string
                    example: user_123
                  timestamp:
                    type: string
                    format: date-time
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/dashboard/personalization:
    get:
      summary: Get Personalization
      description: /dashboard/personalization endpoint.
      tags:
        - Dashboard
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/dashboard/recent-activity:
    get:
      summary: Get recent dashboard activity
      description: >-
        Returns a list of recent activities including invoices, transactions,
        and other financial events
      tags:
        - Dashboard
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: limit
          schema:
            type: integer
            default: 10
          description: Maximum number of activities to return
      responses:
        '200':
          description: Recent activities retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  activities:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: activity_123
                        type:
                          type: string
                          enum:
                            - invoice
                            - transaction
                            - expense
                            - payment
                        description:
                          type: string
                          example: Invoice
                        amount:
                          type: number
                          example: 1250
                        timestamp:
                          type: string
                          format: date-time
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/dashboard/seed-sample-data:
    post:
      summary: Create or submit Seed Sample Data
      description: /dashboard/seed-sample-data endpoint.
      tags:
        - Dashboard
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /dashboard/top-products:
    get:
      summary: Get top revenue products/services
      description: >-
        Returns top revenue-generating services/products for the authenticated
        user. Query params sortBy (revenue|count), limit.
      tags:
        - dashboard
      parameters:
        - in: query
          name: sortBy
          schema:
            type: string
            enum:
              - revenue
              - count
        - in: query
          name: limit
          schema:
            type: integer
      responses:
        '200':
          description: Top products array
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/data-sharing/consents/{id}/revoke:
    post:
      summary: Create or submit Revoke
      description: /data-sharing/consents/{id}/revoke endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/data-sharing/consents/{id}:
    get:
      summary: Get resource
      description: /data-sharing/consents/{id} endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /data-sharing/consents/{id} endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /data-sharing/consents/{id} endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/data-sharing/consents/history:
    get:
      summary: Get History
      description: /data-sharing/consents/history endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/data-sharing/consents:
    get:
      summary: Get Consents
      description: /data-sharing/consents endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Consents
      description: /data-sharing/consents endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/data-sharing/logs:
    get:
      summary: Get Logs
      description: /data-sharing/logs endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/data-sharing/partners/{id}:
    get:
      summary: Get resource
      description: /data-sharing/partners/{id} endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/data-sharing/partners:
    get:
      summary: Get Partners
      description: /data-sharing/partners endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/data-sharing/share:
    post:
      summary: Create or submit Share
      description: /data-sharing/share endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/data-sharing/statistics:
    get:
      summary: Get Statistics
      description: /data-sharing/statistics endpoint.
      tags:
        - Data-Sharing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/developer/api-keys/{id}:
    get:
      summary: Get API key by ID
      description: Retrieves a specific API key with usage statistics
      tags:
        - Developer
        - API Keys
      security:
        - BearerAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: API key ID
      responses:
        '200':
          description: API key retrieved successfully
        '401':
          description: Unauthorized
        '404':
          description: API key not found
        '500':
          description: Internal server error
    patch:
      summary: Update API key
      description: Updates an API key's name, permissions, or status
      tags:
        - Developer
        - API Keys
      security:
        - BearerAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: API key ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                permissions:
                  type: array
                  items:
                    type: string
                status:
                  type: string
                  enum:
                    - active
                    - inactive
                    - revoked
      responses:
        '200':
          description: API key updated successfully
        '400':
          description: Invalid request data
        '401':
          description: Unauthorized
        '404':
          description: API key not found
        '500':
          description: Internal server error
    delete:
      summary: Delete API key
      description: Soft deletes an API key by setting its status to deleted
      tags:
        - Developer
        - API Keys
      security:
        - BearerAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: API key ID
      responses:
        '200':
          description: API key deleted successfully
        '401':
          description: Unauthorized
        '404':
          description: API key not found
        '500':
          description: Internal server error
  /api/developer/endpoints:
    get:
      summary: List API endpoints
      description: >-
        Returns a catalog of available API endpoints by scanning the API routes
        directory, with metadata and usage stats.
      tags:
        - Developer
      security:
        - BearerAuth: []
      responses:
        '200':
          description: Endpoints catalog and stats
          content:
            application/json:
              schema:
                type: object
                properties:
                  endpoints:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        name:
                          type: string
                        description:
                          type: string
                        method:
                          type: string
                        path:
                          type: string
                        category:
                          type: string
                        status:
                          type: string
                        version:
                          type: string
                  stats:
                    type: object
                    properties:
                      totalEndpoints:
                        type: number
                      activeEndpoints:
                        type: number
                      uptime:
                        type: number
                      averageResponseTime:
                        type: number
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/developer:
    get:
      summary: List API keys
      description: >-
        Get all API keys for the current user with usage statistics and monthly
        limits.
      tags:
        - Developer
      security:
        - BearerAuth: []
      responses:
        '200':
          description: List of API keys with usage
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: string
                    name:
                      type: string
                    monthly_usage:
                      type: number
                    monthly_limit:
                      type: number
                    last_used_at:
                      type: string
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create API key
      description: Create a new API key with name, permissions, and optional monthly limit.
      tags:
        - Developer
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - permissions
              properties:
                name:
                  type: string
                permissions:
                  type: array
                  items:
                    type: string
                monthlyLimit:
                  type: number
                  default: 10000
      responses:
        '201':
          description: API key created (key returned once; store securely)
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  name:
                    type: string
                  key:
                    type: string
                  permissions:
                    type: array
                  monthlyLimit:
                    type: number
                  status:
                    type: string
        '400':
          description: Missing name or permissions
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    patch:
      summary: Get API usage statistics
      description: Get usage statistics for the last N days (query param days, default 30).
      tags:
        - Developer
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: days
          schema:
            type: integer
            default: 30
          description: Number of days to include
      responses:
        '200':
          description: Usage stats by date
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    date:
                      type: string
                    requests:
                      type: number
                    errors:
                      type: number
                    avg_response_time:
                      type: number
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    put:
      summary: Record API usage
      description: >-
        Internal endpoint to record API usage (called by API middleware).
        Requires valid API key in body.
      tags:
        - Developer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - apiKey
                - endpoint
              properties:
                apiKey:
                  type: string
                endpoint:
                  type: string
                method:
                  type: string
                statusCode:
                  type: number
                responseTime:
                  type: number
      responses:
        '200':
          description: Usage recorded
        '400':
          description: Missing apiKey or endpoint
        '401':
          description: Invalid API key
        '429':
          description: Rate limit exceeded
        '500':
          description: Internal server error
  /developer/sdk-analytics:
    get:
      summary: Get SDK download analytics
      description: >-
        Returns analytics and metrics for SDK downloads. Admin only. Query
        period (7d, 30d, 90d, all) and sdkType (javascript, python, php, all).
      tags:
        - developer
        - sdk-analytics
      parameters:
        - in: query
          name: period
          schema:
            type: string
            enum:
              - 7d
              - 30d
              - 90d
              - all
            default: 30d
          description: Time period for analytics.
        - in: query
          name: sdkType
          schema:
            type: string
            enum:
              - javascript
              - python
              - php
              - all
            default: all
          description: Filter by SDK type.
      responses:
        '200':
          description: SDK analytics object
        '401':
          description: Unauthorized
        '403':
          description: Admin access required
        '500':
          description: Internal server error
  /developer/sdk-download:
    post:
      summary: Track SDK download
      description: >-
        Records an SDK download for analytics. Requires authentication. Body
        sdkType (javascript, python, php).
      tags:
        - developer
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - sdkType
              properties:
                sdkType:
                  type: string
                  enum:
                    - javascript
                    - python
                    - php
      responses:
        '200':
          description: Download recorded
        '400':
          description: Invalid JSON or invalid SDK type
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/diaspora/businesses/{id}/financial-profile:
    get:
      summary: Get Financial Profile
      description: /diaspora/businesses/{id}/financial-profile endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/diaspora/businesses/{id}/loan-recommendations:
    get:
      summary: Get Loan Recommendations
      description: /diaspora/businesses/{id}/loan-recommendations endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/diaspora/businesses/{id}/tax-optimization:
    get:
      summary: Get Tax Optimization
      description: /diaspora/businesses/{id}/tax-optimization endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /diaspora/cohorts:
    get:
      summary: Get diaspora cohort analytics
      description: >-
        Returns cohort analytics. Query params cohortId, periods (default 12).
        Requires authentication.
      tags:
        - diaspora
        - analytics
      parameters:
        - in: query
          name: cohortId
          schema:
            type: string
        - in: query
          name: periods
          schema:
            type: integer
            default: 12
      responses:
        '200':
          description: Cohort analytics data
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create diaspora cohort
      description: >-
        Creates a new cohort. Body requires cohortName, cohortType (monthly,
        regional, category, custom), startDate; optional endDate, region,
        category, organizationIds. Requires authentication.
      tags:
        - diaspora
        - analytics
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - cohortName
                - cohortType
                - startDate
              properties:
                cohortName:
                  type: string
                cohortType:
                  type: string
                  enum:
                    - monthly
                    - regional
                    - category
                    - custom
                startDate:
                  type: string
                  format: date-time
                endDate:
                  type: string
                  format: date-time
                region:
                  type: string
                category:
                  type: string
                organizationIds:
                  type: array
                  items:
                    type: string
      responses:
        '201':
          description: Created cohort
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/diaspora/cross-border/analytics:
    get:
      summary: Get Analytics
      description: /diaspora/cross-border/analytics endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/diaspora/cross-border/recommendations:
    get:
      summary: Get Recommendations
      description: /diaspora/cross-border/recommendations endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/diaspora/cross-border/transactions:
    get:
      summary: Get Transactions
      description: /diaspora/cross-border/transactions endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Transactions
      description: /diaspora/cross-border/transactions endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/diaspora/insights/community:
    get:
      summary: Get Community
      description: /diaspora/insights/community endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/diaspora/insights/personalized:
    get:
      summary: Get Personalized
      description: /diaspora/insights/personalized endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/diaspora/platforms/{id}/businesses:
    get:
      summary: Get Businesses
      description: /diaspora/platforms/{id}/businesses endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/diaspora/platforms/{id}:
    get:
      summary: Get resource
      description: /diaspora/platforms/{id} endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /diaspora/platforms/{id} endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /diaspora/platforms/{id} endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/diaspora/platforms/{id}/sync:
    post:
      summary: Create or submit Sync
      description: /diaspora/platforms/{id}/sync endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/diaspora/platforms/{id}/test-connection:
    post:
      summary: Create or submit Test Connection
      description: /diaspora/platforms/{id}/test-connection endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/diaspora/platforms:
    get:
      summary: Get Platforms
      description: /diaspora/platforms endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Platforms
      description: /diaspora/platforms endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/diaspora/playbooks:
    get:
      summary: Get Playbooks
      description: /diaspora/playbooks endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/diaspora/pr-conecta/register:
    post:
      summary: Create or submit Register
      description: /diaspora/pr-conecta/register endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/diaspora/pr-credit-readiness:
    get:
      summary: Get Pr Credit Readiness
      description: /diaspora/pr-credit-readiness endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Pr Credit Readiness
      description: /diaspora/pr-credit-readiness endpoint.
      tags:
        - Diaspora
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /diaspora/products:
    get:
      summary: List diaspora financial products
      description: >-
        Returns loan/financial products from CDFIs, cooperativas, and community
        lenders (PR/diaspora-friendly). Requires authentication.
      tags:
        - diaspora
        - products
      parameters:
        - in: query
          name: lenderType
          schema:
            type: string
          description: Filter by lender type (single value).
        - in: query
          name: productType
          schema:
            type: string
          description: Filter by product type.
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
          description: Max results (capped at 100).
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
          description: Pagination offset.
      responses:
        '200':
          description: List of products in body.products
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/direct-file/{...path}:
    get:
      summary: Get resource
      description: /direct-file/{...path} endpoint.
      tags:
        - Direct-File
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit resource
      description: /direct-file/{...path} endpoint.
      tags:
        - Direct-File
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /direct-file/{...path} endpoint.
      tags:
        - Direct-File
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /direct-file/{...path} endpoint.
      tags:
        - Direct-File
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /direct-file/{...path} endpoint.
      tags:
        - Direct-File
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/direct-file/state-api/{...path}:
    get:
      summary: Get resource
      description: /direct-file/state-api/{...path} endpoint.
      tags:
        - Direct-File
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit resource
      description: /direct-file/state-api/{...path} endpoint.
      tags:
        - Direct-File
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/docs:
    get:
      summary: Get Docs
      description: /docs endpoint.
      tags:
        - Docs
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/email/send-invoice:
    post:
      summary: Create or submit Send Invoice
      description: /email/send-invoice endpoint.
      tags:
        - Email
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/embed-finance:
    post:
      summary: Create or submit Embed Finance
      description: /embed-finance endpoint.
      tags:
        - Embed-Finance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/employees/{id}/attendance:
    get:
      summary: Get Attendance
      description: /employees/{id}/attendance endpoint.
      tags:
        - Employees
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/employees/{id}/leave:
    get:
      summary: Get Leave
      description: /employees/{id}/leave endpoint.
      tags:
        - Employees
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/employees/{id}/payroll:
    get:
      summary: Get Payroll
      description: /employees/{id}/payroll endpoint.
      tags:
        - Employees
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /employees/{id}:
    get:
      summary: Get employee by ID
      description: Returns a single employee by ID for the authenticated user.
      tags:
        - employees
        - hr
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Employee ID
      responses:
        '200':
          description: Employee object
        '401':
          description: Unauthorized
        '404':
          description: Employee not found
        '500':
          description: Internal server error
    patch:
      summary: Update employee
      description: >-
        Updates an existing employee. Accepts firstName, lastName, email,
        position, department, status, etc.
      tags:
        - employees
        - hr
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                firstName:
                  type: string
                lastName:
                  type: string
                email:
                  type: string
                status:
                  type: string
                  enum:
                    - active
                    - on_leave
                    - terminated
                    - suspended
      responses:
        '200':
          description: Updated employee
        '400':
          description: Invalid JSON
        '401':
          description: Unauthorized
        '404':
          description: Employee not found
        '500':
          description: Internal server error
    delete:
      summary: Delete employee
      description: Deletes an employee for the authenticated user.
      tags:
        - employees
        - hr
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
        '401':
          description: Unauthorized
        '404':
          description: Employee not found
        '500':
          description: Internal server error
  /employees/analytics:
    get:
      summary: Get employee analytics
      description: >-
        Returns employee analytics for the authenticated user (from
        EmployeesService).
      tags:
        - employees
        - analytics
      responses:
        '200':
          description: Employee analytics object
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /employees/departments:
    get:
      summary: List departments
      description: >-
        Returns departments for an organization. Query param organizationId
        required. Requires authentication.
      tags:
        - employees
        - hr
      parameters:
        - in: query
          name: organizationId
          required: true
          schema:
            type: string
      responses:
        '200':
          description: List of departments
        '400':
          description: organizationId required
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create department
      description: >-
        Creates a new department. Body requires organizationId and name;
        optional description. Requires authentication.
      tags:
        - employees
        - hr
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - organizationId
                - name
              properties:
                organizationId:
                  type: string
                name:
                  type: string
                description:
                  type: string
      responses:
        '201':
          description: Created department
        '400':
          description: Invalid JSON or organizationId/name required
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /employees:
    get:
      summary: List employees
      description: >-
        Returns employees with optional filters (search, department, status).
        Requires authentication.
      tags:
        - employees
        - hr
      parameters:
        - in: query
          name: search
          schema:
            type: string
        - in: query
          name: department
          schema:
            type: string
        - in: query
          name: status
          schema:
            type: string
      responses:
        '200':
          description: List of employees
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create employee
      description: >-
        Creates a new employee. Requires userId, organizationId, firstName,
        lastName, email, position, department, startDate.
      tags:
        - employees
        - hr
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - userId
                - organizationId
                - firstName
                - lastName
                - email
                - position
                - department
                - startDate
              properties:
                userId:
                  type: string
                organizationId:
                  type: string
                  format: uuid
                firstName:
                  type: string
                lastName:
                  type: string
                email:
                  type: string
                phone:
                  type: string
                position:
                  type: string
                department:
                  type: string
                status:
                  type: string
                  enum:
                    - active
                    - on_leave
                    - terminated
                    - suspended
      responses:
        '201':
          description: Created employee
        '400':
          description: Invalid JSON or validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/errors/support-ticket:
    post:
      summary: Create or submit Support Ticket
      description: /errors/support-ticket endpoint.
      tags:
        - Errors
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/expenses/{id}/approve:
    post:
      summary: Create or submit Approve
      description: /expenses/{id}/approve endpoint.
      tags:
        - Expenses
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/expenses/{id}/reject:
    post:
      summary: Create or submit Reject
      description: /expenses/{id}/reject endpoint.
      tags:
        - Expenses
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/expenses/{id}:
    get:
      summary: Get resource
      description: /expenses/{id} endpoint.
      tags:
        - Expenses
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /expenses/{id} endpoint.
      tags:
        - Expenses
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /expenses/{id} endpoint.
      tags:
        - Expenses
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /expenses/analytics:
    get:
      summary: Get expense analytics
      description: >-
        Returns expense analytics for the authenticated user (totals, counts,
        budget comparison) for the given timeframe (7d, 30d, 90d, 1y).
      tags:
        - expenses
        - analytics
      parameters:
        - in: query
          name: timeframe
          schema:
            type: string
            enum:
              - 7d
              - 30d
              - 90d
              - 1y
            default: 30d
          description: Time period for analytics.
      responses:
        '200':
          description: Expense analytics object
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/expenses/categories:
    get:
      summary: Get Categories
      description: /expenses/categories endpoint.
      tags:
        - Expenses
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Categories
      description: /expenses/categories endpoint.
      tags:
        - Expenses
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/expenses:
    get:
      summary: Get list of expenses
      description: >-
        Retrieves a paginated list of expenses with optional filtering by
        status, category, and date range
      tags:
        - Financial
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
          description: Page number for pagination
        - in: query
          name: limit
          schema:
            type: integer
            default: 10
          description: Number of items per page
        - in: query
          name: status
          schema:
            type: string
            enum:
              - pending
              - approved
              - rejected
          description: Filter expenses by approval status
        - in: query
          name: category
          schema:
            type: string
          description: Filter expenses by category
        - in: query
          name: startDate
          schema:
            type: string
            format: date
          description: Start date for filtering (YYYY-MM-DD)
        - in: query
          name: endDate
          schema:
            type: string
            format: date
          description: End date for filtering (YYYY-MM-DD)
      responses:
        '200':
          description: Expenses retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: expense_123
                        amount:
                          type: number
                          example: 150
                        category:
                          type: string
                          example: Office Supplies
                        status:
                          type: string
                          enum:
                            - pending
                            - approved
                            - rejected
                        date:
                          type: string
                          format: date-time
                  pagination:
                    type: object
                    properties:
                      page:
                        type: integer
                      limit:
                        type: integer
                      total:
                        type: integer
                      pages:
                        type: integer
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Create a new expense
      description: Creates a new expense record for the authenticated user
      tags:
        - Financial
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - amount
                - category
                - date
              properties:
                amount:
                  type: number
                  example: 150
                category:
                  type: string
                  example: Office Supplies
                description:
                  type: string
                  example: Printer paper and ink cartridges
                date:
                  type: string
                  format: date-time
                receiptUrl:
                  type: string
                  format: uri
                status:
                  type: string
                  enum:
                    - pending
                    - approved
                    - rejected
                  default: pending
                vendor:
                  type: string
                  example: Office Depot
      responses:
        '201':
          description: Expense created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: Expense created successfully
                  data:
                    type: object
                    properties:
                      id:
                        type: string
                        example: expense_123
                      amount:
                        type: number
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/expenses/stats:
    get:
      summary: Get Stats
      description: /expenses/stats endpoint.
      tags:
        - Expenses
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/feature-flags/{key}/disable:
    post:
      summary: Create or submit Disable
      description: /feature-flags/{key}/disable endpoint.
      tags:
        - Feature-Flags
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/feature-flags/{key}/enable:
    post:
      summary: Create or submit Enable
      description: /feature-flags/{key}/enable endpoint.
      tags:
        - Feature-Flags
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/feature-flags/{key}:
    get:
      summary: Get resource
      description: /feature-flags/{key} endpoint.
      tags:
        - Feature-Flags
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /feature-flags/{key} endpoint.
      tags:
        - Feature-Flags
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /feature-flags/{key} endpoint.
      tags:
        - Feature-Flags
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/feature-flags/check:
    get:
      summary: Get Check
      description: /feature-flags/check endpoint.
      tags:
        - Feature-Flags
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/feature-flags:
    get:
      summary: Get Feature Flags
      description: /feature-flags endpoint.
      tags:
        - Feature-Flags
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Feature Flags
      description: /feature-flags endpoint.
      tags:
        - Feature-Flags
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/feedback:
    post:
      summary: Create or submit Feedback
      description: /feedback endpoint.
      tags:
        - Feedback
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/{type}/config:
    get:
      summary: Get Config
      description: /financial-intelligence/{type}/config endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update Config
      description: /financial-intelligence/{type}/config endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/financial-intelligence/agent:
    post:
      summary: Create or submit Agent
      description: /financial-intelligence/agent endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/ai-readiness:
    get:
      summary: Get Ai Readiness
      description: /financial-intelligence/ai-readiness endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/charts:
    get:
      summary: Get Charts
      description: /financial-intelligence/charts endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/embed-knowledge:
    post:
      summary: Create or submit Embed Knowledge
      description: /financial-intelligence/embed-knowledge endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/embed:
    post:
      summary: Create or submit Embed
      description: /financial-intelligence/embed endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/health:
    get:
      summary: Get Health
      description: /financial-intelligence/health endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/insights/{id}/action:
    post:
      summary: Create or submit Action
      description: /financial-intelligence/insights/{id}/action endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/insights:
    get:
      summary: Get Insights
      description: /financial-intelligence/insights endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/models/{id}/retrain:
    post:
      summary: Create or submit Retrain
      description: /financial-intelligence/models/{id}/retrain endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/predictions:
    get:
      summary: Get Predictions
      description: /financial-intelligence/predictions endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/recommendations:
    get:
      summary: Get Recommendations
      description: /financial-intelligence/recommendations endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/recommendations/schedule:
    post:
      summary: Create or submit Schedule
      description: /financial-intelligence/recommendations/schedule endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/reconcile:
    post:
      summary: Create or submit Reconcile
      description: /financial-intelligence/reconcile endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/risk-assessment:
    get:
      summary: Get Risk Assessment
      description: /financial-intelligence/risk-assessment endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Risk Assessment
      description: /financial-intelligence/risk-assessment endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/scenarios/{id}:
    get:
      summary: Get resource
      description: /financial-intelligence/scenarios/{id} endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/financial-intelligence/scenarios/analyze:
    post:
      summary: Create or submit Analyze
      description: /financial-intelligence/scenarios/analyze endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/scenarios/compare:
    post:
      summary: Create or submit Compare
      description: /financial-intelligence/scenarios/compare endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/scenarios:
    get:
      summary: Get Scenarios
      description: /financial-intelligence/scenarios endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Scenarios
      description: /financial-intelligence/scenarios endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/semantic-query:
    post:
      summary: Create or submit Semantic Query
      description: /financial-intelligence/semantic-query endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/semantic-search:
    post:
      summary: Create or submit Semantic Search
      description: /financial-intelligence/semantic-search endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/settings:
    get:
      summary: Get Settings
      description: /financial-intelligence/settings endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Settings
      description: /financial-intelligence/settings endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/financial-intelligence/startup-metrics:
    get:
      summary: Get Startup Metrics
      description: /financial-intelligence/startup-metrics endpoint.
      tags:
        - Financial-Intelligence
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /freelancers/{id}:
    get:
      summary: Get freelancer by ID
      description: Returns a single freelancer by ID for the authenticated user.
      tags:
        - freelancers
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Freelancer ID
      responses:
        '200':
          description: freelancer object
        '401':
          description: Unauthorized
        '404':
          description: Freelancer not found
        '500':
          description: Internal server error
    put:
      summary: Update freelancer
      description: Updates an existing freelancer profile. Requires authentication.
      tags:
        - freelancers
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                displayName:
                  type: string
                bio:
                  type: string
                skills:
                  type: array
                  items:
                    type: string
                hourlyRate:
                  type: number
                currency:
                  type: string
      responses:
        '200':
          description: Updated freelancer
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '404':
          description: Freelancer not found
        '500':
          description: Internal server error
  /freelancers/dashboard:
    get:
      summary: Get freelancer dashboard
      description: >-
        Returns freelancer platform dashboard statistics (top freelancers,
        project counts, earnings, platform stats).
      tags:
        - freelancers
        - dashboard
      responses:
        '200':
          description: Dashboard object
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /freelancers/me:
    get:
      summary: Get current user freelancer profile
      description: >-
        Returns the authenticated user's freelancer profile. Requires
        authentication.
      tags:
        - freelancers
      responses:
        '200':
          description: success and freelancer object
        '401':
          description: Unauthorized
        '404':
          description: No freelancer profile found
        '500':
          description: Internal server error
  /api/freelancers:
    get:
      summary: Get Freelancers
      description: /freelancers endpoint.
      tags:
        - Freelancers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Freelancers
      description: /freelancers endpoint.
      tags:
        - Freelancers
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/gallery/{id}:
    get:
      summary: Get resource
      description: /gallery/{id} endpoint.
      tags:
        - Gallery
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /gallery/{id} endpoint.
      tags:
        - Gallery
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /gallery/{id} endpoint.
      tags:
        - Gallery
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/gallery/categories:
    get:
      summary: Get Categories
      description: /gallery/categories endpoint.
      tags:
        - Gallery
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Categories
      description: /gallery/categories endpoint.
      tags:
        - Gallery
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/gallery:
    get:
      summary: Get Gallery
      description: /gallery endpoint.
      tags:
        - Gallery
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Gallery
      description: /gallery endpoint.
      tags:
        - Gallery
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/glitchtip-tunnel:
    post:
      summary: Create or submit Glitchtip Tunnel
      description: /glitchtip-tunnel endpoint.
      tags:
        - Glitchtip-Tunnel
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/graph/health:
    get:
      summary: Get Health
      description: /graph/health endpoint.
      tags:
        - Graph
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/guides/{id}:
    get:
      summary: Get resource
      description: /guides/{id} endpoint.
      tags:
        - Guides
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/guides:
    get:
      summary: Get Guides
      description: /guides endpoint.
      tags:
        - Guides
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/guides/slug/{slug}:
    get:
      summary: Get resource
      description: /guides/slug/{slug} endpoint.
      tags:
        - Guides
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/guides/stats:
    get:
      summary: Get Stats
      description: /guides/stats endpoint.
      tags:
        - Guides
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/health:
    get:
      summary: Health check endpoint
      description: >-
        Returns comprehensive health status of the application including
        database, services, and system metrics. Used for monitoring and uptime
        checks.
      tags:
        - Analytics
      responses:
        '200':
          description: Service is healthy or degraded
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum:
                      - healthy
                      - degraded
                      - unhealthy
                    example: healthy
                  timestamp:
                    type: string
                    format: date-time
                  database:
                    type: object
                    properties:
                      status:
                        type: string
                      responseTime:
                        type: number
                  services:
                    type: object
                    description: Status of various services
        '503':
          description: Service is unhealthy
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: unhealthy
                  error:
                    type: string
  /api/help-center/support-tickets:
    get:
      summary: Get Support Tickets
      description: /help-center/support-tickets endpoint.
      tags:
        - Help-Center
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Support Tickets
      description: /help-center/support-tickets endpoint.
      tags:
        - Help-Center
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/help/articles/{id}/feedback:
    post:
      summary: Create or submit Feedback
      description: /help/articles/{id}/feedback endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /help/articles/{id}:
    get:
      summary: Get help article by ID or slug
      description: >-
        Returns a single help article by numeric ID or slug. Only published
        articles. Records view. Requires authentication.
      tags:
        - help
        - articles
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Article ID (numeric) or slug
      responses:
        '200':
          description: Article object
        '401':
          description: Unauthorized
        '404':
          description: Article not found or not published
        '500':
          description: Internal server error
    patch:
      summary: Update help article
      description: Updates an existing help article. Author or admin only.
      tags:
        - help
        - articles
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                title:
                  type: string
                slug:
                  type: string
                content:
                  type: string
                status:
                  type: string
                  enum:
                    - draft
                    - published
      responses:
        '200':
          description: Updated article
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Article not found
        '500':
          description: Internal server error
    delete:
      summary: Delete help article
      description: Deletes a help article. Author or admin only.
      tags:
        - help
        - articles
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
        '401':
          description: Unauthorized
        '403':
          description: Forbidden
        '404':
          description: Article not found
        '500':
          description: Internal server error
  /api/help/articles/{id}/versions:
    get:
      summary: Get Versions
      description: /help/articles/{id}/versions endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Versions
      description: /help/articles/{id}/versions endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/help/articles/bulk-download:
    get:
      summary: Get Bulk Download
      description: /help/articles/bulk-download endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Bulk Download
      description: /help/articles/bulk-download endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/help/articles:
    get:
      summary: List help articles
      description: >-
        Returns help center articles with optional filters (categoryId, status,
        featured, sort) and pagination (limit, offset).
      tags:
        - Help
      parameters:
        - in: query
          name: categoryId
          schema:
            type: integer
        - in: query
          name: status
          schema:
            type: string
            enum:
              - draft
              - published
              - archived
        - in: query
          name: featured
          schema:
            type: boolean
        - in: query
          name: sort
          schema:
            type: string
            enum:
              - recent
              - popular
              - featured
        - in: query
          name: limit
          schema:
            type: integer
        - in: query
          name: offset
          schema:
            type: integer
      responses:
        '200':
          description: List of help articles
        '401':
          description: Unauthorized
    post:
      summary: Create help article
      description: >-
        Creates a new help article. Required fields title, slug, content,
        categoryId.
      tags:
        - Help
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - title
                - slug
                - content
                - categoryId
              properties:
                title:
                  type: string
                slug:
                  type: string
                content:
                  type: string
                excerpt:
                  type: string
                categoryId:
                  type: integer
                status:
                  type: string
                  enum:
                    - draft
                    - published
                    - archived
                  default: draft
                priority:
                  type: number
                  default: 0
                featured:
                  type: boolean
                  default: false
                metaTitle:
                  type: string
                metaDescription:
                  type: string
                tags:
                  type: array
                  items:
                    type: string
                keywords:
                  type: array
                  items:
                    type: string
                tableOfContents:
                  type: array
                attachments:
                  type: array
                version:
                  type: string
                  default: 1.0.0
                parentId:
                  type: string
                isLatest:
                  type: boolean
                  default: true
      responses:
        '201':
          description: Article created
        '400':
          description: Missing required fields
        '401':
          description: Unauthorized
  /api/help/bookmarks:
    get:
      summary: Get Bookmarks
      description: /help/bookmarks endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Bookmarks
      description: /help/bookmarks endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/help/categories:
    get:
      summary: Get Categories
      description: /help/categories endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Categories
      description: /help/categories endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/help/search:
    get:
      summary: Get Search
      description: /help/search endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/help/tickets:
    get:
      summary: Get Tickets
      description: /help/tickets endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Tickets
      description: /help/tickets endpoint.
      tags:
        - Help
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/home/add-sample-data:
    post:
      summary: Create or submit Add Sample Data
      description: /home/add-sample-data endpoint.
      tags:
        - Home
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/home/check-database:
    get:
      summary: Get Check Database
      description: /home/check-database endpoint.
      tags:
        - Home
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/home/metrics:
    get:
      summary: Get public home page metrics
      description: >-
        Returns aggregated platform-wide metrics for the public home page (no
        authentication required)
      tags:
        - Home
      responses:
        '200':
          description: Home metrics retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      revenue:
                        type: object
                        properties:
                          total:
                            type: number
                          thisMonth:
                            type: number
                          lastMonth:
                            type: number
                          growth:
                            type: number
                          formatted:
                            type: string
                      efficiency:
                        type: object
                        properties:
                          timeSaved:
                            type: number
                          change:
                            type: number
                          formatted:
                            type: string
                      accuracy:
                        type: object
                        properties:
                          rate:
                            type: number
                          change:
                            type: number
                          formatted:
                            type: string
                      totalUsers:
                        type: number
                      totalClients:
                        type: number
                      totalInvoices:
                        type: number
                      platformUptime:
                        type: number
        '500':
          description: Internal server error
  /api/home/stats:
    get:
      summary: Get public platform statistics
      description: >-
        Returns aggregated platform statistics for the public home page (no
        authentication required)
      tags:
        - Home
      responses:
        '200':
          description: Platform stats retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  data:
                    type: object
                    properties:
                      totalUsers:
                        type: number
                      totalClients:
                        type: number
                      totalRevenue:
                        type: string
                      avgRating:
                        type: number
                      formatted:
                        type: object
                        properties:
                          users:
                            type: string
                          clients:
                            type: string
                          revenue:
                            type: string
                          rating:
                            type: string
        '500':
          description: Internal server error
  /api/home/test:
    get:
      summary: Get Test
      description: /home/test endpoint.
      tags:
        - Home
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/home/testimonials:
    get:
      summary: Get user testimonials
      description: >-
        Returns user testimonials for the public home page (no authentication
        required)
      tags:
        - Home
      parameters:
        - in: query
          name: limit
          schema:
            type: integer
            default: 3
          description: Maximum number of testimonials to return
      responses:
        '200':
          description: Testimonials retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                        name:
                          type: string
                        role:
                          type: string
                        company:
                          type: string
                        avatar:
                          type: string
                        content:
                          type: string
                        rating:
                          type: number
                        metric:
                          type: string
                        createdAt:
                          type: string
        '500':
          description: Internal server error
  /api/hr/attendance/clock-in:
    post:
      summary: Clock in
      description: >-
        Records clock-in for the authenticated user. Body validated by
        clockInSchema (e.g. location, notes).
      tags:
        - HR
        - Attendance
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                location:
                  type: string
                notes:
                  type: string
      responses:
        '201':
          description: Clock-in record created
        '400':
          description: Validation error
        '401':
          description: Unauthorized
  /api/hr/attendance/clock-out:
    post:
      summary: Clock out
      description: >-
        Records clock-out for the authenticated user. Body validated by
        clockOutSchema (e.g. location, notes).
      tags:
        - HR
        - Attendance
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                location:
                  type: string
                notes:
                  type: string
      responses:
        '200':
          description: Clock-out record updated
        '400':
          description: Validation error
        '401':
          description: Unauthorized
  /api/hr/attendance/records:
    get:
      summary: List attendance records
      description: >-
        Returns attendance records with optional filters (employeeId,
        contractorId, organizationId, status, startDate, endDate). Requires
        authentication.
      tags:
        - HR
        - Attendance
      parameters:
        - in: query
          name: employeeId
          schema:
            type: string
        - in: query
          name: contractorId
          schema:
            type: string
        - in: query
          name: organizationId
          schema:
            type: string
        - in: query
          name: status
          schema:
            type: string
        - in: query
          name: startDate
          schema:
            type: string
            format: date-time
        - in: query
          name: endDate
          schema:
            type: string
            format: date-time
      responses:
        '200':
          description: List of attendance records
        '401':
          description: Unauthorized
  /api/hr/attendance/stats:
    get:
      summary: Get attendance statistics
      description: >-
        Returns attendance stats for an employee or contractor. Query employeeId
        or contractorId (one required); optional startDate, endDate.
      tags:
        - HR
        - Attendance
      parameters:
        - in: query
          name: employeeId
          schema:
            type: string
        - in: query
          name: contractorId
          schema:
            type: string
        - in: query
          name: startDate
          schema:
            type: string
            format: date-time
        - in: query
          name: endDate
          schema:
            type: string
            format: date-time
      responses:
        '200':
          description: Attendance statistics
        '400':
          description: Either employeeId or contractorId is required
        '401':
          description: Unauthorized
  /api/hr/attendance/time-cards/{id}:
    patch:
      summary: Update time card (submit/approve/reject)
      description: >-
        Submits, approves, or rejects a time card. Body status (submitted,
        approved, rejected); optional rejectionReason for reject. Requires
        authentication.
      tags:
        - HR
        - Attendance
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Time card ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - status
              properties:
                status:
                  type: string
                  enum:
                    - submitted
                    - approved
                    - rejected
                rejectionReason:
                  type: string
      responses:
        '200':
          description: Updated time card
        '400':
          description: Invalid status update or validation error
        '401':
          description: Unauthorized
  /api/hr/attendance/time-cards:
    get:
      summary: List time cards
      description: >-
        Returns time cards with optional filters (employeeId, contractorId,
        organizationId, status, payPeriodStart, payPeriodEnd). Requires
        authentication.
      tags:
        - HR
        - Attendance
      parameters:
        - in: query
          name: employeeId
          schema:
            type: string
        - in: query
          name: contractorId
          schema:
            type: string
        - in: query
          name: organizationId
          schema:
            type: string
        - in: query
          name: status
          schema:
            type: string
        - in: query
          name: payPeriodStart
          schema:
            type: string
            format: date-time
        - in: query
          name: payPeriodEnd
          schema:
            type: string
            format: date-time
      responses:
        '200':
          description: List of time cards
        '401':
          description: Unauthorized
    post:
      summary: Create or submit/approve time card
      description: >-
        Creates a new time card or submits/approves one. Body validated by
        createTimeCardSchema or action. Requires authentication.
      tags:
        - HR
        - Attendance
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                employeeId:
                  type: string
                contractorId:
                  type: string
                organizationId:
                  type: string
                action:
                  type: string
                  enum:
                    - submit
                    - approve
      responses:
        '200':
          description: Time card created or updated
        '400':
          description: Validation error
        '401':
          description: Unauthorized
  /api/hr/contractors/{id}/performance:
    get:
      summary: Get Performance
      description: /hr/contractors/{id}/performance endpoint.
      tags:
        - Hr
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /hr/contractors/{id}:
    get:
      summary: Get contractor by ID
      description: Returns a single contractor by ID. Requires authentication.
      tags:
        - hr
        - contractors
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Contractor ID
      responses:
        '200':
          description: Contractor object
        '401':
          description: Unauthorized
        '404':
          description: Contractor not found
        '500':
          description: Internal server error
    patch:
      summary: Update contractor
      description: >-
        Updates an existing contractor. Body validated by
        updateContractorSchema. Requires authentication.
      tags:
        - hr
        - contractors
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                email:
                  type: string
                status:
                  type: string
                contractStartDate:
                  type: string
                  format: date
      responses:
        '200':
          description: Updated contractor
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    delete:
      summary: Delete contractor
      description: Deletes a contractor. Requires authentication.
      tags:
        - hr
        - contractors
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
        '401':
          description: Unauthorized
        '404':
          description: Contractor not found
        '500':
          description: Internal server error
  /hr/contractors:
    get:
      summary: List contractors
      description: >-
        Returns contractors with optional filters (search, contractorType,
        status, organizationId). Requires authentication.
      tags:
        - hr
        - contractors
      parameters:
        - in: query
          name: search
          schema:
            type: string
        - in: query
          name: contractorType
          schema:
            type: string
        - in: query
          name: status
          schema:
            type: string
        - in: query
          name: organizationId
          schema:
            type: string
      responses:
        '200':
          description: List of contractors
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create contractor
      description: Creates a new contractor. Body validated by createContractorSchema.
      tags:
        - hr
        - contractors
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                email:
                  type: string
                contractorType:
                  type: string
                organizationId:
                  type: string
                status:
                  type: string
      responses:
        '201':
          description: Created contractor
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/hr/employees/{id}/tax-info:
    get:
      summary: Get Tax Info
      description: /hr/employees/{id}/tax-info endpoint.
      tags:
        - Hr
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Tax Info
      description: /hr/employees/{id}/tax-info endpoint.
      tags:
        - Hr
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/hr/employees/tax-info/w2-data:
    get:
      summary: Get W2 Data
      description: /hr/employees/tax-info/w2-data endpoint.
      tags:
        - Hr
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /hr/leave/balances/{employeeId}:
    get:
      summary: Get leave balance for employee
      description: >-
        Returns leave balance for the given employee. Optional query param
        leaveTypeId. Requires authentication.
      tags:
        - hr
        - leave
      parameters:
        - in: path
          name: employeeId
          required: true
          schema:
            type: string
          description: Employee ID
        - in: query
          name: leaveTypeId
          schema:
            type: string
      responses:
        '200':
          description: Leave balance data
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /hr/leave/calendar:
    get:
      summary: Get leave calendar
      description: >-
        Returns leave calendar view for an organization and date range. Query
        params organizationId, startDate, endDate required. Requires
        authentication.
      tags:
        - hr
        - leave
      parameters:
        - in: query
          name: organizationId
          required: true
          schema:
            type: string
        - in: query
          name: startDate
          required: true
          schema:
            type: string
            format: date
        - in: query
          name: endDate
          required: true
          schema:
            type: string
            format: date
      responses:
        '200':
          description: Leave calendar data
        '400':
          description: organizationId
          startDate: null
          endDate required: null
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /hr/leave/requests/{id}:
    patch:
      summary: Approve or reject leave request
      description: >-
        Approves or rejects a leave request. Body approved (boolean), optional
        rejectionReason. Requires authentication.
      tags:
        - hr
        - leave
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Leave request ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - approved
              properties:
                approved:
                  type: boolean
                rejectionReason:
                  type: string
      responses:
        '200':
          description: Updated leave request
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '404':
          description: Leave request not found
        '500':
          description: Internal server error
  /hr/leave/requests:
    get:
      summary: List leave requests
      description: >-
        Returns leave requests with optional filters (employeeId,
        organizationId, status, startDate, endDate). Requires authentication.
      tags:
        - hr
        - leave
      parameters:
        - in: query
          name: employeeId
          schema:
            type: string
        - in: query
          name: organizationId
          schema:
            type: string
        - in: query
          name: status
          schema:
            type: string
        - in: query
          name: startDate
          schema:
            type: string
            format: date
        - in: query
          name: endDate
          schema:
            type: string
            format: date
      responses:
        '200':
          description: List of leave requests
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Submit or approve leave request
      description: >-
        Submits a new leave request or approves/rejects an existing one. Body
        varies by action.
      tags:
        - hr
        - leave
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                action:
                  type: string
                  enum:
                    - submit
                    - approve
                    - reject
                requestId:
                  type: string
                startDate:
                  type: string
                endDate:
                  type: string
                leaveTypeId:
                  type: string
                reason:
                  type: string
      responses:
        '200':
          description: Created or updated leave request
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /hr/leave/types:
    get:
      summary: List leave types
      description: >-
        Returns leave types for an organization. Query param organizationId
        required. Requires authentication.
      tags:
        - hr
        - leave
      parameters:
        - in: query
          name: organizationId
          required: true
          schema:
            type: string
      responses:
        '200':
          description: List of leave types
        '400':
          description: organizationId required
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create leave type
      description: >-
        Creates a new leave type for the organization. Body validated by
        createLeaveTypeSchema. Requires authentication.
      tags:
        - hr
        - leave
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                organizationId:
                  type: string
                name:
                  type: string
                daysAllowed:
                  type: number
                carryOver:
                  type: boolean
      responses:
        '201':
          description: Created leave type
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/hr/payroll/benefits:
    get:
      summary: List payroll benefits
      description: >-
        Returns benefits for an organization. Query organizationId (required);
        employeeId, contractorId optional.
      tags:
        - HR
        - Payroll
      parameters:
        - in: query
          name: organizationId
          required: true
          schema:
            type: string
        - in: query
          name: employeeId
          schema:
            type: string
        - in: query
          name: contractorId
          schema:
            type: string
      responses:
        '200':
          description: List of benefits
        '400':
          description: organizationId is required
        '401':
          description: Unauthorized
    post:
      summary: Create payroll benefit
      description: Creates a new benefit. Body validated by createPayrollBenefitSchema.
      tags:
        - HR
        - Payroll
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        '200':
          description: Created benefit
        '400':
          description: Validation error
        '401':
          description: Unauthorized
  /api/hr/payroll/deductions:
    get:
      summary: List payroll deductions
      description: >-
        Returns deductions for an organization. Query organizationId (required);
        employeeId, contractorId optional.
      tags:
        - HR
        - Payroll
      parameters:
        - in: query
          name: organizationId
          required: true
          schema:
            type: string
        - in: query
          name: employeeId
          schema:
            type: string
        - in: query
          name: contractorId
          schema:
            type: string
      responses:
        '200':
          description: List of deductions
        '400':
          description: organizationId is required
        '401':
          description: Unauthorized
    post:
      summary: Create payroll deduction
      description: Creates a new deduction. Body validated by createPayrollDeductionSchema.
      tags:
        - HR
        - Payroll
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        '200':
          description: Created deduction
        '400':
          description: Validation error
        '401':
          description: Unauthorized
  /api/hr/payroll/employees/{id}/history:
    get:
      summary: Get employee payroll history
      description: >-
        Returns payroll history for an employee. Query limit (optional, default
        12).
      tags:
        - HR
        - Payroll
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Employee ID
        - in: query
          name: limit
          schema:
            type: integer
            default: 12
      responses:
        '200':
          description: List of payroll history entries
        '401':
          description: Unauthorized
  /api/hr/payroll/employees/{id}/paystub:
    get:
      summary: Get employee pay stub
      description: >-
        Generates pay stub for an employee. Uses latest payroll entry if entryId
        not provided. Query entryId (optional) for a specific entry.
      tags:
        - HR
        - Payroll
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Employee ID
        - in: query
          name: entryId
          schema:
            type: string
          description: Optional; specific payroll entry ID
      responses:
        '200':
          description: Pay stub data
        '401':
          description: Unauthorized
        '404':
          description: No payroll entries found for employee
  /api/hr/payroll/export:
    post:
      summary: Export payroll data
      description: >-
        Exports payroll data for a given payroll run. Body payrollRunId
        (required), format (e.g. csv). Requires authentication.
      tags:
        - HR
        - Payroll
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - payrollRunId
              properties:
                payrollRunId:
                  type: string
                format:
                  type: string
                  default: csv
      responses:
        '200':
          description: Export data (format-dependent)
        '400':
          description: payrollRunId is required
        '401':
          description: Unauthorized
  /api/hr/payroll:
    get:
      summary: Get payroll overview
      description: >-
        Returns payroll runs (paginated), employee payroll entries, stats, and
        monthly trend. Requires active organization.
      tags:
        - HR
        - Payroll
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
        - in: query
          name: limit
          schema:
            type: integer
            default: 20
        - in: query
          name: status
          schema:
            type: string
        - in: query
          name: period
          schema:
            type: string
      responses:
        '200':
          description: Payroll runs, employeePayroll, stats, pagination
        '400':
          description: Organization ID required
        '401':
          description: Unauthorized
    post:
      summary: Payroll action
      description: >-
        Process, approve, reject, or export payroll. Body action (process,
        approve, reject, export) and optional payrollRunId, employeeIds.
      tags:
        - HR
        - Payroll
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                action:
                  type: string
                  enum:
                    - process
                    - approve
                    - reject
                    - export
                payrollRunId:
                  type: string
                employeeIds:
                  type: array
                  items:
                    type: string
      responses:
        '200':
          description: Action result
        '400':
          description: Invalid action
        '401':
          description: Unauthorized
  /api/hr/payroll/runs/{id}/entries:
    get:
      summary: Get payroll run entries
      description: >-
        Returns payroll entries for a given payroll run. Requires
        authentication.
      tags:
        - HR
        - Payroll
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Payroll run ID
      responses:
        '200':
          description: List of payroll entries for the run
        '401':
          description: Unauthorized
  /api/hr/payroll/runs/{id}:
    get:
      summary: Get payroll run by ID
      description: Returns a single payroll run by ID.
      tags:
        - HR
        - Payroll
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Payroll run ID
      responses:
        '200':
          description: Payroll run details
        '401':
          description: Unauthorized
        '404':
          description: Payroll run not found
    post:
      summary: Process payroll run
      description: >-
        Processes the payroll run; optional employeeIds and contractorIds in
        body.
      tags:
        - HR
        - Payroll
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Payroll run ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                employeeIds:
                  type: array
                  items:
                    type: string
                contractorIds:
                  type: array
                  items:
                    type: string
      responses:
        '200':
          description: Process result
        '401':
          description: Unauthorized
  /hr/payroll/runs:
    get:
      summary: List payroll runs
      description: >-
        Returns payroll runs with optional filters (organizationId, status,
        startDate, endDate). Requires authentication.
      tags:
        - hr
        - payroll
      parameters:
        - in: query
          name: organizationId
          schema:
            type: string
        - in: query
          name: status
          schema:
            type: string
        - in: query
          name: startDate
          schema:
            type: string
            format: date
        - in: query
          name: endDate
          schema:
            type: string
            format: date
      responses:
        '200':
          description: List of payroll runs
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create or process payroll run
      description: >-
        Creates a new payroll run or processes payroll. Body action (process)
        with runId or create payload. Requires authentication.
      tags:
        - hr
        - payroll
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                action:
                  type: string
                  enum:
                    - process
                runId:
                  type: string
                organizationId:
                  type: string
      responses:
        '200':
          description: Payroll run or process result
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/hr/payroll/taxes:
    get:
      summary: List payroll tax configuration
      description: >-
        Returns tax configuration for an organization. Query organizationId
        (required).
      tags:
        - HR
        - Payroll
      parameters:
        - in: query
          name: organizationId
          required: true
          schema:
            type: string
      responses:
        '200':
          description: List of tax configurations
        '400':
          description: organizationId is required
        '401':
          description: Unauthorized
    post:
      summary: Create payroll tax configuration
      description: >-
        Creates a new tax configuration. Body validated by
        createPayrollTaxSchema.
      tags:
        - HR
        - Payroll
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        '200':
          description: Created tax configuration
        '400':
          description: Validation error
        '401':
          description: Unauthorized
  /api/incident-response/drills/{id}/complete:
    post:
      summary: Create or submit Complete
      description: /incident-response/drills/{id}/complete endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/incident-response/drills:
    get:
      summary: Get Drills
      description: /incident-response/drills endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Drills
      description: /incident-response/drills endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/incident-response/incidents/{id}:
    get:
      summary: Get resource
      description: /incident-response/incidents/{id} endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /incident-response/incidents/{id} endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/incident-response/incidents:
    get:
      summary: Get Incidents
      description: /incident-response/incidents endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Incidents
      description: /incident-response/incidents endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/incident-response/metrics:
    get:
      summary: Get Metrics
      description: /incident-response/metrics endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/incident-response/runbooks:
    get:
      summary: Get Runbooks
      description: /incident-response/runbooks endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Runbooks
      description: /incident-response/runbooks endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/incident-response/team:
    get:
      summary: Get Team
      description: /incident-response/team endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Team
      description: /incident-response/team endpoint.
      tags:
        - Incident-Response
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/integrations/{id}/config:
    get:
      summary: Get Config
      description: /integrations/{id}/config endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Config
      description: /integrations/{id}/config endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/integrations/{id}:
    get:
      summary: Get resource
      description: /integrations/{id} endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/integrations/connections/{id}/health:
    get:
      summary: Get Health
      description: /integrations/connections/{id}/health endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/integrations/connections/{id}:
    get:
      summary: Get resource
      description: /integrations/connections/{id} endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /integrations/connections/{id} endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /integrations/connections/{id} endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/integrations/connections/{id}/sync:
    post:
      summary: Create or submit Sync
      description: /integrations/connections/{id}/sync endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/integrations/connections/{id}/syncs:
    get:
      summary: Get Syncs
      description: /integrations/connections/{id}/syncs endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/integrations/connections/{id}/test:
    post:
      summary: Create or submit Test
      description: /integrations/connections/{id}/test endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/integrations/connections:
    get:
      summary: Get Connections
      description: /integrations/connections endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Connections
      description: /integrations/connections endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/integrations/connections/test:
    post:
      summary: Create or submit Test
      description: /integrations/connections/test endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/integrations/gumroad:
    get:
      summary: Get Gumroad
      description: /integrations/gumroad endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Gumroad
      description: /integrations/gumroad endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/integrations/oauth/{service}/authorize:
    get:
      summary: Get Authorize
      description: /integrations/oauth/{service}/authorize endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/integrations/oauth/{service}/callback:
    get:
      summary: Get Callback
      description: /integrations/oauth/{service}/callback endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/integrations/oauth/{service}/refresh:
    post:
      summary: Create or submit Refresh
      description: /integrations/oauth/{service}/refresh endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/integrations/providers:
    get:
      summary: Get Providers
      description: /integrations/providers endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/integrations:
    get:
      summary: Get available integrations
      description: >-
        Retrieves a paginated list of available third-party integrations
        (accounting software, payment processors, etc.)
      tags:
        - Integrations
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: category
          schema:
            type: string
          description: Filter integrations by category (accounting, payment, crm, etc.)
        - in: query
          name: search
          schema:
            type: string
          description: Search term for integration name or description
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
          description: Maximum number of integrations to return
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
          description: Number of integrations to skip
      responses:
        '200':
          description: Integrations retrieved successfully
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: string
                      example: integration_123
                    name:
                      type: string
                      example: QuickBooks
                    description:
                      type: string
                    category:
                      type: string
                      example: accounting
                    isOfficial:
                      type: boolean
                      example: true
                    isActive:
                      type: boolean
                      example: true
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/integrations/shopify:
    get:
      summary: Get Shopify
      description: /integrations/shopify endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Shopify
      description: /integrations/shopify endpoint.
      tags:
        - Integrations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /integrations/webhooks:
    post:
      summary: Handle partner webhooks
      description: >-
        Handle incoming webhooks from partner services (Stripe, Gusto,
        QuickBooks, Xero, PayPal, Shopify).
      tags:
        - integrations
      requestBody:
        content:
          application/json: {}
      responses:
        '200':
          description: Webhook processed
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/investor-portal/{portalId}:
    get:
      summary: Get resource
      description: /investor-portal/{portalId} endpoint.
      tags:
        - Investor-Portal
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/investor-portal:
    get:
      summary: Get Investor Portal
      description: /investor-portal endpoint.
      tags:
        - Investor-Portal
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Investor Portal
      description: /investor-portal endpoint.
      tags:
        - Investor-Portal
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/invoices/{id}/details:
    get:
      summary: Get invoice details
      description: Returns full invoice with client, payments, and payment summary.
      tags:
        - Invoices
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Invoice ID
      responses:
        '200':
          description: Invoice, client, payments, paymentSummary
        '401':
          description: Unauthorized
        '404':
          description: Invoice not found
  /api/invoices/{id}/download:
    get:
      summary: Download invoice
      description: Returns the invoice as HTML (suitable for conversion to PDF by client).
      tags:
        - Invoices
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Invoice ID
      responses:
        '200':
          description: Invoice HTML (Content-Type text/html)
        '401':
          description: Unauthorized
        '404':
          description: Invoice not found
  /invoices/{id}:
    get:
      summary: Get invoice by ID
      description: Returns a single invoice by ID for the authenticated user.
      tags:
        - invoices
        - financial
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Invoice ID
      responses:
        '200':
          description: Invoice object
        '400':
          description: Invalid invoice ID
        '401':
          description: Unauthorized
        '404':
          description: Invoice not found
        '500':
          description: Internal server error
    put:
      summary: Update invoice
      description: >-
        Updates an existing invoice. Body may include status, dueDate,
        lineItems, clientId, etc. Requires authentication.
      tags:
        - invoices
        - financial
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                dueDate:
                  type: string
                  format: date
                lineItems:
                  type: array
                clientId:
                  type: string
      responses:
        '200':
          description: Updated invoice
        '400':
          description: Invalid JSON or invoice ID
        '401':
          description: Unauthorized
        '404':
          description: Invoice not found
        '500':
          description: Internal server error
    delete:
      summary: Delete invoice
      description: Deletes an invoice for the authenticated user.
      tags:
        - invoices
        - financial
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
        '400':
          description: Invalid invoice ID
        '401':
          description: Unauthorized
        '404':
          description: Invoice not found
        '500':
          description: Internal server error
  /api/invoices:
    get:
      summary: Get list of invoices
      description: >-
        Retrieves a paginated list of invoices for the authenticated user. Uses
        Row Level Security (RLS) to ensure users can only access their own
        invoices.
      tags:
        - Financial
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
          description: Page number for pagination
        - in: query
          name: limit
          schema:
            type: integer
            default: 10
          description: Number of items per page
      responses:
        '200':
          description: Invoices retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: invoice_123
                        invoiceNumber:
                          type: string
                          example: INV-2025-001
                        clientId:
                          type: string
                        amount:
                          type: number
                          example: 1250
                        status:
                          type: string
                          enum:
                            - draft
                            - sent
                            - paid
                            - overdue
                            - cancelled
                        dueDate:
                          type: string
                          format: date-time
                  pagination:
                    type: object
                    properties:
                      page:
                        type: integer
                      limit:
                        type: integer
                      total:
                        type: integer
                      pages:
                        type: integer
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Create a new invoice
      description: >-
        Creates a new invoice for the authenticated user. Uses Row Level
        Security (RLS) to ensure invoices are associated with the correct user.
      tags:
        - Financial
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - clientId
                - amount
                - invoiceNumber
              properties:
                clientId:
                  type: string
                  example: client_123
                invoiceNumber:
                  type: string
                  example: INV-2025-001
                amount:
                  type: number
                  example: 1250
                currency:
                  type: string
                  default: USD
                description:
                  type: string
                  example: Monthly consulting services
                dueDate:
                  type: string
                  format: date-time
                status:
                  type: string
                  enum:
                    - draft
                    - sent
                    - paid
                    - overdue
                    - cancelled
                  default: draft
      responses:
        '201':
          description: Invoice created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  data:
                    type: object
                    properties:
                      id:
                        type: string
                        example: invoice_123
                      invoiceNumber:
                        type: string
                      amount:
                        type: number
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/invoices/templates:
    get:
      summary: List invoice templates
      description: Returns all invoice templates for the authenticated user.
      tags:
        - Invoices
      responses:
        '200':
          description: List of templates (success, templates)
        '401':
          description: Unauthorized
    post:
      summary: Create template or invoice from template
      description: >-
        With action create_from_template creates an invoice from a template;
        otherwise creates a new template.
      tags:
        - Invoices
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                action:
                  type: string
                  enum:
                    - create_from_template
                templateId:
                  type: string
                name:
                  type: string
                description:
                  type: string
                terms:
                  type: string
                footer:
                  type: string
                defaultItems:
                  type: array
                taxRate:
                  type: number
                paymentTerms:
                  type: string
                isDefault:
                  type: boolean
      responses:
        '201':
          description: Template or invoice created
        '400':
          description: Template ID or name required
        '401':
          description: Unauthorized
  /api/items/{entityType}/{entityId}/{action}:
    post:
      summary: Create or submit resource
      description: /items/{entityType}/{entityId}/{action} endpoint.
      tags:
        - Items
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/items/{entityType}/{entityId}/is-pinned:
    get:
      summary: Get Is Pinned
      description: /items/{entityType}/{entityId}/is-pinned endpoint.
      tags:
        - Items
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/items/{entityType}/{entityId}/logs:
    get:
      summary: Get Logs
      description: /items/{entityType}/{entityId}/logs endpoint.
      tags:
        - Items
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/jurisdictions/primary:
    post:
      summary: Create or submit Primary
      description: /jurisdictions/primary endpoint.
      tags:
        - Jurisdictions
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/jurisdictions:
    get:
      summary: Get Jurisdictions
      description: /jurisdictions endpoint.
      tags:
        - Jurisdictions
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Jurisdictions
      description: /jurisdictions endpoint.
      tags:
        - Jurisdictions
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    delete:
      summary: Delete Jurisdictions
      description: /jurisdictions endpoint.
      tags:
        - Jurisdictions
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/kyc/pr-validate:
    get:
      summary: Get Pr Validate
      description: /kyc/pr-validate endpoint.
      tags:
        - Kyc
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Pr Validate
      description: /kyc/pr-validate endpoint.
      tags:
        - Kyc
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/leads/{id}:
    get:
      summary: Get resource
      description: /leads/{id} endpoint.
      tags:
        - Leads
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /leads/{id} endpoint.
      tags:
        - Leads
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /leads/{id} endpoint.
      tags:
        - Leads
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/leads/activities:
    post:
      summary: Create or submit Activities
      description: /leads/activities endpoint.
      tags:
        - Leads
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/leads/pipeline:
    get:
      summary: Get Pipeline
      description: /leads/pipeline endpoint.
      tags:
        - Leads
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/leads:
    get:
      summary: Get list of leads
      description: >-
        Retrieves a paginated list of sales leads with optional filtering by
        status, source, priority, and assignment
      tags:
        - Analytics
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
          description: Page number for pagination
        - in: query
          name: limit
          schema:
            type: integer
            default: 20
          description: Number of items per page
        - in: query
          name: search
          schema:
            type: string
          description: Search term for lead name, email, or company
        - in: query
          name: status
          schema:
            type: string
            enum:
              - new
              - contacted
              - qualified
              - proposal
              - negotiation
              - closed_won
              - closed_lost
              - nurturing
          description: Filter leads by status
        - in: query
          name: source
          schema:
            type: string
            enum:
              - website
              - referral
              - social_media
              - email_campaign
              - cold_call
              - trade_show
              - advertisement
              - partner
              - other
          description: Filter leads by source
        - in: query
          name: priority
          schema:
            type: string
            enum:
              - low
              - medium
              - high
              - urgent
          description: Filter leads by priority
        - in: query
          name: assignedTo
          schema:
            type: string
          description: Filter leads by assigned user ID
      responses:
        '200':
          description: Leads retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: lead_123
                        firstName:
                          type: string
                          example: John
                        lastName:
                          type: string
                          example: Doe
                        email:
                          type: string
                          format: email
                        company:
                          type: string
                        status:
                          type: string
                          enum:
                            - new
                            - contacted
                            - qualified
                            - proposal
                            - negotiation
                            - closed_won
                            - closed_lost
                            - nurturing
                        source:
                          type: string
                        estimatedValue:
                          type: number
                          example: 50000
                  pagination:
                    type: object
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Create a new lead
      description: >-
        Creates a new sales lead with contact information, source tracking, and
        pipeline management
      tags:
        - Analytics
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - firstName
                - lastName
                - email
                - source
              properties:
                firstName:
                  type: string
                  example: John
                lastName:
                  type: string
                  example: Doe
                email:
                  type: string
                  format: email
                  example: john.doe@example.com
                phone:
                  type: string
                  example: +1-555-0123
                company:
                  type: string
                  example: Acme Corp
                jobTitle:
                  type: string
                  example: CEO
                website:
                  type: string
                  format: uri
                source:
                  type: string
                  enum:
                    - website
                    - referral
                    - social_media
                    - email_campaign
                    - cold_call
                    - trade_show
                    - advertisement
                    - partner
                    - other
                  example: website
                priority:
                  type: string
                  enum:
                    - low
                    - medium
                    - high
                    - urgent
                  default: medium
                estimatedValue:
                  type: number
                  example: 50000
                probability:
                  type: number
                  minimum: 0
                  maximum: 100
                  example: 75
                expectedCloseDate:
                  type: string
                  format: date-time
                assignedTo:
                  type: string
                  description: User ID to assign the lead to
                tags:
                  type: array
                  items:
                    type: string
                  example:
                    - enterprise
                    - saas
                notes:
                  type: string
      responses:
        '201':
          description: Lead created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  lead:
                    type: object
                    properties:
                      id:
                        type: string
                        example: lead_123
                      firstName:
                        type: string
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/leads/stats:
    get:
      summary: Get Stats
      description: /leads/stats endpoint.
      tags:
        - Leads
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/lending/applications:
    get:
      summary: Get Applications
      description: /lending/applications endpoint.
      tags:
        - Lending
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Applications
      description: /lending/applications endpoint.
      tags:
        - Lending
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/lending/invoice-financing/{invoiceId}/eligibility:
    get:
      summary: Get Eligibility
      description: /lending/invoice-financing/{invoiceId}/eligibility endpoint.
      tags:
        - Lending
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/lending/invoice-financing:
    get:
      summary: Get Invoice Financing
      description: /lending/invoice-financing endpoint.
      tags:
        - Lending
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Invoice Financing
      description: /lending/invoice-financing endpoint.
      tags:
        - Lending
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/lending/lenders:
    get:
      summary: Get Lenders
      description: /lending/lenders endpoint.
      tags:
        - Lending
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/lending/pre-qualify:
    get:
      summary: Get Pre Qualify
      description: /lending/pre-qualify endpoint.
      tags:
        - Lending
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Pre Qualify
      description: /lending/pre-qualify endpoint.
      tags:
        - Lending
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/market-tracking/benchmarks:
    get:
      summary: Get Benchmarks
      description: /market-tracking/benchmarks endpoint.
      tags:
        - Market-Tracking
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Benchmarks
      description: /market-tracking/benchmarks endpoint.
      tags:
        - Market-Tracking
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/market-tracking/competitors:
    get:
      summary: Get Competitors
      description: /market-tracking/competitors endpoint.
      tags:
        - Market-Tracking
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Competitors
      description: /market-tracking/competitors endpoint.
      tags:
        - Market-Tracking
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/market-tracking/market-size:
    get:
      summary: Get Market Size
      description: /market-tracking/market-size endpoint.
      tags:
        - Market-Tracking
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Market Size
      description: /market-tracking/market-size endpoint.
      tags:
        - Market-Tracking
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/market-tracking/news:
    get:
      summary: Get News
      description: /market-tracking/news endpoint.
      tags:
        - Market-Tracking
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit News
      description: /market-tracking/news endpoint.
      tags:
        - Market-Tracking
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketing/ab-tests/{id}:
    get:
      summary: Get resource
      description: /marketing/ab-tests/{id} endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /marketing/ab-tests/{id} endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/marketing/ab-tests:
    get:
      summary: Get Ab Tests
      description: /marketing/ab-tests endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Ab Tests
      description: /marketing/ab-tests endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /marketing/analytics:
    get:
      summary: Get marketing campaign analytics
      description: >-
        Returns campaign analytics for the authenticated user. Use dateRange
        (7d, 30d, 90d, 1y) or startDate/endDate; optional campaignId and
        platform filters.
      tags:
        - marketing
        - analytics
      parameters:
        - in: query
          name: dateRange
          schema:
            type: string
            enum:
              - 7d
              - 30d
              - 90d
              - 1y
          description: Preset range (alternative to startDate/endDate).
        - in: query
          name: startDate
          schema:
            type: string
            format: date
          description: Start date (with endDate).
        - in: query
          name: endDate
          schema:
            type: string
            format: date
          description: End date (with startDate).
        - in: query
          name: campaignId
          schema:
            type: string
          description: Filter by campaign ID.
        - in: query
          name: platform
          schema:
            type: string
          description: Filter by platform.
      responses:
        '200':
          description: Campaign analytics object
        '400':
          description: Invalid date range
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/marketing/automation/{id}:
    get:
      summary: Get resource
      description: /marketing/automation/{id} endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /marketing/automation/{id} endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/marketing/automation:
    get:
      summary: Get Automation
      description: /marketing/automation endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Automation
      description: /marketing/automation endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketing/case-studies:
    get:
      summary: Get Case Studies
      description: /marketing/case-studies endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketing/conversions:
    post:
      summary: Create or submit Conversions
      description: /marketing/conversions endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketing/funnel:
    get:
      summary: Get Funnel
      description: /marketing/funnel endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Funnel
      description: /marketing/funnel endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketing/videos:
    get:
      summary: Get Videos
      description: /marketing/videos endpoint.
      tags:
        - Marketing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/bids/{id}/accept:
    post:
      summary: Create or submit Accept
      description: /marketplace/bids/{id}/accept endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/connect/create-account:
    post:
      summary: Create or submit Create Account
      description: /marketplace/connect/create-account endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/contracts/{id}:
    get:
      summary: Get resource
      description: /marketplace/contracts/{id} endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/marketplace/contracts:
    post:
      summary: Create or submit Contracts
      description: /marketplace/contracts endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/developer/earnings:
    get:
      summary: Get Earnings
      description: /marketplace/developer/earnings endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/escrow/{transactionId}/release:
    post:
      summary: Create or submit Release
      description: /marketplace/escrow/{transactionId}/release endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/listings/{id}/bids:
    get:
      summary: Get Bids
      description: /marketplace/listings/{id}/bids endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Bids
      description: /marketplace/listings/{id}/bids endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/listings/{id}:
    get:
      summary: Get resource
      description: /marketplace/listings/{id} endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /marketplace/listings/{id} endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /marketplace/listings:
    get:
      summary: List marketplace listings
      description: >-
        Returns marketplace listings with optional filters (type, category,
        search, limit, offset). Requires authentication.
      tags:
        - marketplace
      parameters:
        - in: query
          name: type
          schema:
            type: string
            enum:
              - job
              - service
              - project
              - consultation
              - other
        - in: query
          name: category
          schema:
            type: string
        - in: query
          name: search
          schema:
            type: string
        - in: query
          name: limit
          schema:
            type: integer
        - in: query
          name: offset
          schema:
            type: integer
      responses:
        '200':
          description: List of listings
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create marketplace listing
      description: >-
        Creates a new marketplace listing. Body requires title, description,
        type, category; optional budget, tags, startDate, etc. Requires
        authentication.
      tags:
        - marketplace
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - title
                - description
                - type
                - category
              properties:
                title:
                  type: string
                description:
                  type: string
                type:
                  type: string
                  enum:
                    - job
                    - service
                    - project
                    - consultation
                    - other
                category:
                  type: string
                budgetMin:
                  type: number
                budgetMax:
                  type: number
                currency:
                  type: string
                  default: USD
      responses:
        '201':
          description: Created listing
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/marketplace/plugins/{id}/approve:
    post:
      summary: Create or submit Approve
      description: /marketplace/plugins/{id}/approve endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/plugins/{id}/config:
    get:
      summary: Get Config
      description: /marketplace/plugins/{id}/config endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update Config
      description: /marketplace/plugins/{id}/config endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/marketplace/plugins/{id}/flag:
    post:
      summary: Create or submit Flag
      description: /marketplace/plugins/{id}/flag endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/plugins/{id}/install:
    post:
      summary: Create or submit Install
      description: /marketplace/plugins/{id}/install endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/plugins/{id}/like:
    post:
      summary: Create or submit Like
      description: /marketplace/plugins/{id}/like endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/plugins/{id}/reject:
    post:
      summary: Create or submit Reject
      description: /marketplace/plugins/{id}/reject endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/plugins/{id}/reviews/{reviewId}/helpful:
    post:
      summary: Create or submit Helpful
      description: /marketplace/plugins/{id}/reviews/{reviewId}/helpful endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/plugins/{id}:
    get:
      summary: Get resource
      description: /marketplace/plugins/{id} endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/marketplace/plugins/{id}/uninstall:
    delete:
      summary: Delete Uninstall
      description: /marketplace/plugins/{id}/uninstall endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/marketplace/plugins/installed:
    get:
      summary: Get Installed
      description: /marketplace/plugins/installed endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/plugins/my-plugins:
    get:
      summary: Get My Plugins
      description: /marketplace/plugins/my-plugins endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/plugins/pending:
    get:
      summary: Get Pending
      description: /marketplace/plugins/pending endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/plugins:
    get:
      summary: Get Plugins
      description: /marketplace/plugins endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/plugins/submit:
    post:
      summary: Create or submit Submit
      description: /marketplace/plugins/submit endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/pr-conecta/sync:
    post:
      summary: Create or submit Sync
      description: /marketplace/pr-conecta/sync endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/revenue:
    get:
      summary: Get Revenue
      description: /marketplace/revenue endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Revenue
      description: /marketplace/revenue endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    patch:
      summary: Update Revenue
      description: /marketplace/revenue endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/marketplace/reviews:
    get:
      summary: Get Reviews
      description: /marketplace/reviews endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Reviews
      description: /marketplace/reviews endpoint.
      tags:
        - Marketplace
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /marketplace/stats:
    get:
      summary: Get marketplace stats
      description: >-
        Returns the authenticated user marketplace statistics (listings, bids,
        contracts). Requires authentication.
      tags:
        - marketplace
      responses:
        '200':
          description: success and data (listings
          bids: null
          contracts): null
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/metrics:
    get:
      summary: Get Metrics
      description: /metrics endpoint.
      tags:
        - Metrics
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/monitoring/alerts:
    get:
      summary: Get Alerts
      description: /monitoring/alerts endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/monitoring/alerts/rules/{id}:
    get:
      summary: Get resource
      description: /monitoring/alerts/rules/{id} endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /monitoring/alerts/rules/{id} endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/monitoring/alerts/rules:
    get:
      summary: Get Rules
      description: /monitoring/alerts/rules endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Rules
      description: /monitoring/alerts/rules endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/monitoring/alerts/summary:
    get:
      summary: Get Summary
      description: /monitoring/alerts/summary endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/monitoring/errors:
    get:
      summary: Get Errors
      description: /monitoring/errors endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/monitoring/events:
    get:
      summary: Get Events
      description: /monitoring/events endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/monitoring/health:
    get:
      summary: Get Health
      description: /monitoring/health endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/monitoring/metrics:
    get:
      summary: Get Metrics
      description: /monitoring/metrics endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/monitoring/metrics/trends:
    get:
      summary: Get Trends
      description: /monitoring/metrics/trends endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/monitoring/rate-limits:
    get:
      summary: Get Rate Limits
      description: /monitoring/rate-limits endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/monitoring/snapshot-queries:
    get:
      summary: Get Snapshot Queries
      description: /monitoring/snapshot-queries endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Snapshot Queries
      description: /monitoring/snapshot-queries endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/monitoring/webhook-events:
    get:
      summary: Get Webhook Events
      description: /monitoring/webhook-events endpoint.
      tags:
        - Monitoring
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/multi-agent:
    post:
      summary: Create or submit Multi Agent
      description: /multi-agent endpoint.
      tags:
        - Multi-Agent
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/newsletter/subscribe:
    post:
      summary: Create or submit Subscribe
      description: /newsletter/subscribe endpoint.
      tags:
        - Newsletter
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/notifications/{id}/archive:
    post:
      summary: Create or submit Archive
      description: /notifications/{id}/archive endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/notifications/{id}/read:
    post:
      summary: Create or submit Read
      description: /notifications/{id}/read endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/notifications/{id}:
    post:
      summary: Create or submit resource
      description: /notifications/{id} endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /notifications/{id} endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/notifications/bulk-archive:
    post:
      summary: Create or submit Bulk Archive
      description: /notifications/bulk-archive endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/notifications/bulk-delete:
    post:
      summary: Create or submit Bulk Delete
      description: /notifications/bulk-delete endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/notifications/mark-all-read:
    post:
      summary: Create or submit Mark All Read
      description: /notifications/mark-all-read endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/notifications/novu/unread-count:
    get:
      summary: Get Unread Count
      description: /notifications/novu/unread-count endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/notifications/preferences:
    get:
      summary: Get Preferences
      description: /notifications/preferences endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    put:
      summary: Update Preferences
      description: /notifications/preferences endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/notifications:
    get:
      summary: Get user notifications
      description: >-
        Retrieves a paginated list of notifications for the authenticated user
        with optional filtering
      tags:
        - Analytics
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
            minimum: 1
            maximum: 100
          description: Maximum number of notifications to return
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
            minimum: 0
          description: Number of notifications to skip
        - in: query
          name: unreadOnly
          schema:
            type: boolean
            default: false
          description: Return only unread notifications
        - in: query
          name: type
          schema:
            type: string
          description: Filter notifications by type
      responses:
        '200':
          description: Notifications retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  notifications:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: notif_123
                        title:
                          type: string
                          example: Invoice Paid
                        message:
                          type: string
                          example: Invoice
                        type:
                          type: string
                        read:
                          type: boolean
                          example: false
                        createdAt:
                          type: string
                          format: date-time
                  unreadCount:
                    type: integer
                    example: 5
                  pagination:
                    type: object
                    properties:
                      limit:
                        type: integer
                      offset:
                        type: integer
                      total:
                        type: integer
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/notifications/statistics:
    get:
      summary: Get Statistics
      description: /notifications/statistics endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/notifications/templates/{code}/create:
    post:
      summary: Create or submit Create
      description: /notifications/templates/{code}/create endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/notifications/templates/{code}:
    get:
      summary: Get resource
      description: /notifications/templates/{code} endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /notifications/templates/{code} endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /notifications/templates/{code} endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/notifications/templates:
    get:
      summary: Get Templates
      description: /notifications/templates endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Templates
      description: /notifications/templates endpoint.
      tags:
        - Notifications
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/onboarding:
    get:
      summary: Get Onboarding
      description: /onboarding endpoint.
      tags:
        - Onboarding
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Onboarding
      description: /onboarding endpoint.
      tags:
        - Onboarding
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    patch:
      summary: Update Onboarding
      description: /onboarding endpoint.
      tags:
        - Onboarding
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/onboarding/skip:
    post:
      summary: Create or submit Skip
      description: /onboarding/skip endpoint.
      tags:
        - Onboarding
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /onboarding/steps/{stepId}:
    post:
      summary: Complete onboarding step
      description: >-
        Marks an onboarding step as completed. Body may include stepData,
        timeSpent. Requires authentication.
      tags:
        - onboarding
      parameters:
        - in: path
          name: stepId
          required: true
          schema:
            type: string
          description: Onboarding step ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                stepData:
                  type: object
                timeSpent:
                  type: number
      responses:
        '200':
          description: Step completed
          next step or completion payload: null
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '404':
          description: Step not found
        '500':
          description: Internal server error
    patch:
      summary: Skip onboarding step
      description: >-
        Marks an onboarding step as skipped. Body may include reason. Requires
        authentication.
      tags:
        - onboarding
      parameters:
        - in: path
          name: stepId
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                reason:
                  type: string
      responses:
        '200':
          description: Step skipped
        '401':
          description: Unauthorized
        '404':
          description: Step not found
        '500':
          description: Internal server error
  /api/optimization/recommendations/{id}/implement:
    post:
      summary: Create or submit Implement
      description: /optimization/recommendations/{id}/implement endpoint.
      tags:
        - Optimization
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/orders/{id}/fulfill:
    post:
      summary: Create or submit Fulfill
      description: /orders/{id}/fulfill endpoint.
      tags:
        - Orders
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /orders/{id}:
    get:
      summary: Get order by ID
      description: Returns a single order by ID for the authenticated user.
      tags:
        - orders
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Order ID
      responses:
        '200':
          description: Order object
        '401':
          description: Unauthorized
        '404':
          description: Order not found
        '500':
          description: Internal server error
    patch:
      summary: Update order
      description: >-
        Updates an existing order. Body may include status, products,
        shippingAddress, etc. Requires authentication.
      tags:
        - orders
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                  enum:
                    - pending
                    - processing
                    - shipped
                    - delivered
                    - cancelled
                    - refunded
                products:
                  type: array
      responses:
        '200':
          description: Updated order
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/orders/alerts:
    get:
      summary: Get Alerts
      description: /orders/alerts endpoint.
      tags:
        - Orders
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /orders/analytics:
    get:
      summary: Get order analytics
      description: Returns order analytics for the authenticated user (from OrdersService).
      tags:
        - orders
        - analytics
      responses:
        '200':
          description: Order analytics object
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /orders:
    get:
      summary: List orders
      description: >-
        Returns orders with optional filters (search, status, customerId).
        Requires authentication.
      tags:
        - orders
      parameters:
        - in: query
          name: search
          schema:
            type: string
        - in: query
          name: status
          schema:
            type: string
        - in: query
          name: customerId
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: List of orders
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create order
      description: >-
        Creates a new order. Requires products array; optional customerId,
        orderNumber, status, priority, addresses, dueDate.
      tags:
        - orders
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - products
              properties:
                customerId:
                  type: string
                  format: uuid
                orderNumber:
                  type: string
                products:
                  type: array
                  items:
                    type: object
                status:
                  type: string
                  enum:
                    - pending
                    - processing
                    - shipped
                    - delivered
                    - cancelled
                    - refunded
                priority:
                  type: string
                  enum:
                    - low
                    - normal
                    - high
                    - urgent
      responses:
        '201':
          description: Created order
        '400':
          description: Invalid JSON or validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/organizations/{id}/billing/history:
    get:
      summary: Get History
      description: /organizations/{id}/billing/history endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/organizations/{id}/billing/invoices/{invoiceId}:
    get:
      summary: Get resource
      description: /organizations/{id}/billing/invoices/{invoiceId} endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /organizations/{id}/billing:
    get:
      summary: Get organization billing
      description: >-
        Returns subscription and billing info for the organization. Requires
        organization access.
      tags:
        - organizations
        - billing
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Organization ID
      responses:
        '200':
          description: Billing/subscription data
        '403':
          description: Access denied
        '404':
          description: User or organization not found
        '500':
          description: Internal server error
    post:
      summary: Create or update organization subscription
      description: >-
        Creates or updates subscription for the organization. Requires
        organization permission.
      tags:
        - organizations
        - billing
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Organization ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                planId:
                  type: string
                stripePriceId:
                  type: string
      responses:
        '200':
          description: Updated subscription
        '400':
          description: Validation error
        '403':
          description: Access denied
        '404':
          description: User or organization not found
        '500':
          description: Internal server error
  /api/organizations/{id}/diagnostics:
    get:
      summary: Get Diagnostics
      description: /organizations/{id}/diagnostics endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/organizations/{id}/invitations/{invitationId}:
    patch:
      summary: Update resource
      description: /organizations/{id}/invitations/{invitationId} endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/organizations/{id}/invitations:
    get:
      summary: Get Invitations
      description: /organizations/{id}/invitations endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Invitations
      description: /organizations/{id}/invitations endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/organizations/{id}/members/{memberId}/role:
    patch:
      summary: Update Role
      description: /organizations/{id}/members/{memberId}/role endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete Role
      description: /organizations/{id}/members/{memberId}/role endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/organizations/{id}/members:
    get:
      summary: Get Members
      description: /organizations/{id}/members endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/organizations/{id}/role-audit:
    get:
      summary: Get Role Audit
      description: /organizations/{id}/role-audit endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/organizations/{id}:
    get:
      summary: Get resource
      description: /organizations/{id} endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /organizations/{id} endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /organizations/{id} endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/organizations/{id}/settings:
    get:
      summary: Get Settings
      description: /organizations/{id}/settings endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update Settings
      description: /organizations/{id}/settings endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/organizations/{id}/switch:
    post:
      summary: Create or submit Switch
      description: /organizations/{id}/switch endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/organizations/invitations/accept:
    post:
      summary: Create or submit Accept
      description: /organizations/invitations/accept endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/organizations/invitations/decline:
    post:
      summary: Create or submit Decline
      description: /organizations/invitations/decline endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/organizations/locations:
    get:
      summary: Get Locations
      description: /organizations/locations endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Locations
      description: /organizations/locations endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /organizations:
    get:
      summary: List organizations
      description: Returns all organizations the current user belongs to.
      tags:
        - organizations
      responses:
        '200':
          description: Object with success and data (array of organizations)
        '404':
          description: User not found
        '500':
          description: Internal server error
    post:
      summary: Create organization
      description: >-
        Creates a new organization. Requires verified email. Body may include
        name, slug, and email domain validation.
      tags:
        - organizations
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                slug:
                  type: string
      responses:
        '201':
          description: Created organization
        '400':
          description: Validation error or email not verified
        '404':
          description: User not found
        '500':
          description: Internal server error
  /api/organizations/subsidiaries:
    get:
      summary: Get Subsidiaries
      description: /organizations/subsidiaries endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Subsidiaries
      description: /organizations/subsidiaries endpoint.
      tags:
        - Organizations
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/payment-methods/{id}:
    get:
      summary: Get resource
      description: /payment-methods/{id} endpoint.
      tags:
        - Payment-Methods
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /payment-methods/{id} endpoint.
      tags:
        - Payment-Methods
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /payment-methods/{id} endpoint.
      tags:
        - Payment-Methods
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/payment-methods:
    get:
      summary: Get Payment Methods
      description: /payment-methods endpoint.
      tags:
        - Payment-Methods
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Payment Methods
      description: /payment-methods endpoint.
      tags:
        - Payment-Methods
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/payment-methods/setup-intent:
    post:
      summary: Create or submit Setup Intent
      description: /payment-methods/setup-intent endpoint.
      tags:
        - Payment-Methods
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/payments/{id}/receipt:
    get:
      summary: Get Receipt
      description: /payments/{id}/receipt endpoint.
      tags:
        - Payments
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/payments/methods:
    get:
      summary: Get Methods
      description: /payments/methods endpoint.
      tags:
        - Payments
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/payments/orchestration:
    get:
      summary: Get Orchestration
      description: /payments/orchestration endpoint.
      tags:
        - Payments
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Orchestration
      description: /payments/orchestration endpoint.
      tags:
        - Payments
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/payments:
    get:
      summary: Get list of payments
      description: >-
        Retrieves a paginated list of payments with optional filtering by
        status, payment method, and date range
      tags:
        - Financial
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
          description: Page number for pagination
        - in: query
          name: limit
          schema:
            type: integer
            default: 20
          description: Number of items per page
        - in: query
          name: search
          schema:
            type: string
          description: Search term for payment reference or description
        - in: query
          name: status
          schema:
            type: string
            enum:
              - pending
              - processing
              - completed
              - failed
              - cancelled
              - refunded
              - partially_refunded
          description: Filter payments by status
        - in: query
          name: paymentMethodId
          schema:
            type: string
          description: Filter payments by payment method ID
        - in: query
          name: startDate
          schema:
            type: string
            format: date
          description: Start date for filtering (YYYY-MM-DD)
        - in: query
          name: endDate
          schema:
            type: string
            format: date
          description: End date for filtering (YYYY-MM-DD)
      responses:
        '200':
          description: Payments retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: payment_123
                        amount:
                          type: number
                          example: 1250
                        status:
                          type: string
                          enum:
                            - pending
                            - processing
                            - completed
                            - failed
                            - cancelled
                            - refunded
                            - partially_refunded
                        paymentType:
                          type: string
                          enum:
                            - invoice_payment
                            - refund
                            - chargeback
                            - adjustment
                            - transfer
                  pagination:
                    type: object
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Process a payment
      description: >-
        Processes a payment transaction (invoice payment, refund, chargeback,
        adjustment, or transfer)
      tags:
        - Financial
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - paymentMethodId
                - paymentType
                - amount
              properties:
                paymentMethodId:
                  type: string
                  example: pm_123
                  description: ID of the payment method to use
                invoiceId:
                  type: string
                  description: Optional invoice ID if this is an invoice payment
                paymentType:
                  type: string
                  enum:
                    - invoice_payment
                    - refund
                    - chargeback
                    - adjustment
                    - transfer
                  example: invoice_payment
                amount:
                  type: number
                  example: 1250
                currency:
                  type: string
                  default: USD
                description:
                  type: string
                  example: Payment for invoice
                reference:
                  type: string
                notes:
                  type: string
                metadata:
                  type: object
      responses:
        '201':
          description: Payment processed successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  payment:
                    type: object
                    properties:
                      id:
                        type: string
                        example: payment_123
                      amount:
                        type: number
                      status:
                        type: string
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/payments/stats:
    get:
      summary: Get Stats
      description: /payments/stats endpoint.
      tags:
        - Payments
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/paywall/check:
    get:
      summary: Get Check
      description: /paywall/check endpoint.
      tags:
        - Paywall
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/performance/database-size:
    get:
      summary: Get Database Size
      description: /performance/database-size endpoint.
      tags:
        - Performance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/performance/health:
    get:
      summary: Get Health
      description: /performance/health endpoint.
      tags:
        - Performance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/performance/slow-queries:
    get:
      summary: Get Slow Queries
      description: /performance/slow-queries endpoint.
      tags:
        - Performance
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/platform/hub/connections/{id}:
    get:
      summary: Get resource
      description: /platform/hub/connections/{id} endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /platform/hub/connections/{id} endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /platform/hub/connections/{id} endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/platform/hub/connections/{id}/sync:
    get:
      summary: Get Sync
      description: /platform/hub/connections/{id}/sync endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Sync
      description: /platform/hub/connections/{id}/sync endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/platform/hub/connections:
    get:
      summary: Get Connections
      description: /platform/hub/connections endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Connections
      description: /platform/hub/connections endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/platform/hub/integrations:
    get:
      summary: Get Integrations
      description: /platform/hub/integrations endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Integrations
      description: /platform/hub/integrations endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/platform/hub:
    get:
      summary: Get Hub
      description: /platform/hub endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Hub
      description: /platform/hub endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/platform/services/{id}:
    get:
      summary: Get resource
      description: /platform/services/{id} endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /platform/services/{id} endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/platform/services:
    get:
      summary: Get Services
      description: /platform/services endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Services
      description: /platform/services endpoint.
      tags:
        - Platform
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/playbooks/{id}/execute:
    post:
      summary: Create or submit Execute
      description: /playbooks/{id}/execute endpoint.
      tags:
        - Playbooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/playbooks/{id}/executions:
    get:
      summary: Get Executions
      description: /playbooks/{id}/executions endpoint.
      tags:
        - Playbooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/playbooks/{id}:
    get:
      summary: Get resource
      description: /playbooks/{id} endpoint.
      tags:
        - Playbooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /playbooks/executions/{executionId}:
    get:
      summary: Get playbook execution
      description: Returns a single playbook execution by ID for the authenticated user.
      tags:
        - playbooks
      parameters:
        - in: path
          name: executionId
          required: true
          schema:
            type: string
          description: Execution ID
      responses:
        '200':
          description: execution object
        '401':
          description: Unauthorized
        '404':
          description: User or execution not found
        '500':
          description: Internal server error
    patch:
      summary: Update playbook execution status
      description: >-
        Updates execution status (in_progress, completed, paused, cancelled,
        failed). Body may include status, currentStepId, completedSteps,
        metadata. Requires authentication.
      tags:
        - playbooks
      parameters:
        - in: path
          name: executionId
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                  enum:
                    - in_progress
                    - completed
                    - paused
                    - cancelled
                    - failed
                currentStepId:
                  type: string
                completedSteps:
                  type: array
                  items:
                    type: string
                metadata:
                  type: object
      responses:
        '200':
          description: Updated execution
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '404':
          description: Execution not found
        '500':
          description: Internal server error
  /api/playbooks/executions/{executionId}/steps:
    post:
      summary: Create or submit Steps
      description: /playbooks/executions/{executionId}/steps endpoint.
      tags:
        - Playbooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/playbooks/recommendations:
    get:
      summary: Get Recommendations
      description: /playbooks/recommendations endpoint.
      tags:
        - Playbooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/playbooks:
    get:
      summary: Get Playbooks
      description: /playbooks endpoint.
      tags:
        - Playbooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Playbooks
      description: /playbooks endpoint.
      tags:
        - Playbooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/products/{id}:
    get:
      summary: Get resource
      description: /products/{id} endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /products/{id} endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /products/{id} endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/products/{id}/stock:
    patch:
      summary: Update Stock
      description: /products/{id}/stock endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /products/analytics:
    get:
      summary: Get product analytics
      description: >-
        Returns product/order analytics for the active organization. Optional
        timeframe (7d, 30d, 90d, 1y) and productId filter.
      tags:
        - products
        - analytics
      parameters:
        - in: query
          name: timeframe
          schema:
            type: string
            enum:
              - 7d
              - 30d
              - 90d
              - 1y
            default: 30d
          description: Time period for analytics.
        - in: query
          name: productId
          schema:
            type: string
          description: Filter by product ID.
      responses:
        '200':
          description: Product analytics object
        '400':
          description: Organization ID required
        '401':
          description: Unauthorized
        '404':
          description: User not found in database
        '500':
          description: Internal server error
  /api/products/categories:
    get:
      summary: Get Categories
      description: /products/categories endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Categories
      description: /products/categories endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/products/pricing-rules/{id}:
    get:
      summary: Get resource
      description: /products/pricing-rules/{id} endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /products/pricing-rules/{id} endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /products/pricing-rules/{id} endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/products/pricing-rules:
    get:
      summary: Get Pricing Rules
      description: /products/pricing-rules endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Pricing Rules
      description: /products/pricing-rules endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/products:
    get:
      summary: Get Products
      description: /products endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Products
      description: /products endpoint.
      tags:
        - Products
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/profile/aggregate:
    post:
      summary: Create or submit Aggregate
      description: /profile/aggregate endpoint.
      tags:
        - Profile
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /profile:
    get:
      summary: Get user profile
      description: >-
        Returns aggregated user profile (preferences, dashboard layout, widgets,
        etc.). Requires authentication.
      tags:
        - profile
      responses:
        '200':
          description: Unified user profile object
        '401':
          description: Unauthorized
        '404':
          description: User not found
        '500':
          description: Internal server error
    put:
      summary: Update user profile
      description: >-
        Updates user profile (preferences, layout, widgetIds). Rate limited.
        Requires authentication.
      tags:
        - profile
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                preferences:
                  type: object
                dashboardLayout:
                  type: object
                widgetIds:
                  type: array
                  items:
                    type: string
      responses:
        '200':
          description: Updated profile
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '429':
          description: Rate limit exceeded
        '500':
          description: Internal server error
  /projects/{id}:
    get:
      summary: Get project by ID
      description: Returns a single project by ID for the authenticated user.
      tags:
        - projects
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Project ID
      responses:
        '200':
          description: Project object in body.project
        '401':
          description: Unauthorized
        '404':
          description: Project not found
        '500':
          description: Internal server error
    put:
      summary: Update project
      description: >-
        Updates an existing project. Accepts name, description, status,
        priority, dates, budget, etc.
      tags:
        - projects
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Project ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                description:
                  type: string
                status:
                  type: string
                  enum:
                    - planning
                    - active
                    - on_hold
                    - completed
                    - cancelled
                priority:
                  type: string
                  enum:
                    - low
                    - medium
                    - high
                    - urgent
                budget:
                  type: number
                hourlyRate:
                  type: number
      responses:
        '200':
          description: Updated project in body.project
        '400':
          description: Invalid JSON
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/projects:
    get:
      summary: Get list of projects
      description: >-
        Retrieves a paginated list of projects with optional filtering by
        status, priority, and client
      tags:
        - Workflows
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
          description: Page number for pagination
        - in: query
          name: limit
          schema:
            type: integer
            default: 20
          description: Number of items per page
        - in: query
          name: search
          schema:
            type: string
          description: Search term for project name or description
        - in: query
          name: status
          schema:
            type: string
            enum:
              - planning
              - active
              - on_hold
              - completed
              - cancelled
          description: Filter projects by status
        - in: query
          name: priority
          schema:
            type: string
            enum:
              - low
              - medium
              - high
              - urgent
          description: Filter projects by priority
        - in: query
          name: clientId
          schema:
            type: string
          description: Filter projects by client ID
      responses:
        '200':
          description: Projects retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: integer
                          example: 1
                        name:
                          type: string
                          example: Website Redesign
                        status:
                          type: string
                          enum:
                            - planning
                            - active
                            - on_hold
                            - completed
                            - cancelled
                        priority:
                          type: string
                          enum:
                            - low
                            - medium
                            - high
                            - urgent
                        budget:
                          type: number
                          example: 50000
                  pagination:
                    type: object
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Create a new project
      description: Creates a new project for time tracking, billing, and task management
      tags:
        - Workflows
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
              properties:
                name:
                  type: string
                  example: Website Redesign Project
                description:
                  type: string
                  example: Complete redesign of company website
                clientId:
                  type: string
                  example: client_123
                status:
                  type: string
                  enum:
                    - planning
                    - active
                    - on_hold
                    - completed
                    - cancelled
                  default: planning
                priority:
                  type: string
                  enum:
                    - low
                    - medium
                    - high
                    - urgent
                  default: medium
                startDate:
                  type: string
                  format: date-time
                dueDate:
                  type: string
                  format: date-time
                budget:
                  type: number
                  example: 50000
                hourlyRate:
                  type: number
                  example: 150
                currency:
                  type: string
                  default: USD
                isBillable:
                  type: boolean
                  default: true
                estimatedHours:
                  type: number
                  example: 200
                tags:
                  type: array
                  items:
                    type: string
                  example:
                    - web-design
                    - frontend
                    - backend
      responses:
        '201':
          description: Project created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  project:
                    type: object
                    properties:
                      id:
                        type: integer
                        example: 1
                      name:
                        type: string
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/projects/stats:
    get:
      summary: Get Stats
      description: /projects/stats endpoint.
      tags:
        - Projects
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/push/send:
    post:
      summary: Create or submit Send
      description: /push/send endpoint.
      tags:
        - Push
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/push/subscribe:
    post:
      summary: Create or submit Subscribe
      description: /push/subscribe endpoint.
      tags:
        - Push
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    delete:
      summary: Delete Subscribe
      description: /push/subscribe endpoint.
      tags:
        - Push
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/buyer/pre-approval:
    get:
      summary: Get Pre Approval
      description: /real-estate/buyer/pre-approval endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Pre Approval
      description: /real-estate/buyer/pre-approval endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/buyer/saved-properties:
    get:
      summary: Get Saved Properties
      description: /real-estate/buyer/saved-properties endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Saved Properties
      description: /real-estate/buyer/saved-properties endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    delete:
      summary: Delete Saved Properties
      description: /real-estate/buyer/saved-properties endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/buyer/stats:
    get:
      summary: Get Stats
      description: /real-estate/buyer/stats endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/buyer/tours:
    get:
      summary: Get Tours
      description: /real-estate/buyer/tours endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Tours
      description: /real-estate/buyer/tours endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/compliance/{jurisdiction}:
    get:
      summary: Get compliance data for a jurisdiction
      description: >-
        Returns compliance data for the given property jurisdiction
        (puerto_rico, us_mainland, other).
      tags:
        - Real Estate
      security:
        - BearerAuth: []
      parameters:
        - in: path
          name: jurisdiction
          required: true
          schema:
            type: string
            enum:
              - puerto_rico
              - us_mainland
              - other
          description: Property jurisdiction code
      responses:
        '200':
          description: Compliance data for the jurisdiction
          content:
            application/json:
              schema:
                type: object
                properties:
                  compliance:
                    type: object
        '400':
          description: Invalid jurisdiction
        '401':
          description: Unauthorized
        '404':
          description: User not found
        '500':
          description: Internal server error
  /api/real-estate/investor/cash-flow:
    get:
      summary: Get Cash Flow
      description: /real-estate/investor/cash-flow endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/investor/expenses:
    get:
      summary: Get Expenses
      description: /real-estate/investor/expenses endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/investor/maintenance:
    get:
      summary: Get Maintenance
      description: /real-estate/investor/maintenance endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/investor/tenants/{id}:
    get:
      summary: Get a tenant by ID
      description: >-
        Returns a single tenant with property, unit, and lease details for the
        authenticated investor.
      tags:
        - Real Estate
      security:
        - BearerAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Tenant ID
      responses:
        '200':
          description: Tenant details
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                  firstName:
                    type: string
                  lastName:
                    type: string
                  email:
                    type: string
                  status:
                    type: string
                  property:
                    type: object
                  unit:
                    type: object
                  lease:
                    type: object
        '401':
          description: Unauthorized
        '404':
          description: Tenant not found
        '500':
          description: Internal server error
    patch:
      summary: Update a tenant
      description: >-
        Updates tenant information. Supports partial updates for propertyId,
        unitId, contact info, employment, creditScore, status, notes.
      tags:
        - Real Estate
      security:
        - BearerAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Tenant ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                propertyId:
                  type: string
                unitId:
                  type: string
                  format: uuid
                firstName:
                  type: string
                lastName:
                  type: string
                email:
                  type: string
                phone:
                  type: string
                status:
                  type: string
                  enum:
                    - active
                    - inactive
                    - evicted
                    - notice
                creditScore:
                  type: integer
                  minimum: 300
                  maximum: 850
                notes:
                  type: string
      responses:
        '200':
          description: Updated tenant
          content:
            application/json:
              schema:
                type: object
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '404':
          description: Tenant not found
        '500':
          description: Internal server error
  /api/real-estate/investor/tenants:
    get:
      summary: Get Tenants
      description: /real-estate/investor/tenants endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Tenants
      description: /real-estate/investor/tenants endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/jurisdictions/{jurisdiction}/stats:
    get:
      summary: Get jurisdiction statistics
      description: >-
        Returns statistics for the given property jurisdiction (puerto_rico,
        us_mainland, other).
      tags:
        - Real Estate
      security:
        - BearerAuth: []
      parameters:
        - in: path
          name: jurisdiction
          required: true
          schema:
            type: string
            enum:
              - puerto_rico
              - us_mainland
              - other
          description: Property jurisdiction code
      responses:
        '200':
          description: Jurisdiction statistics
          content:
            application/json:
              schema:
                type: object
                properties:
                  stats:
                    type: object
        '400':
          description: Invalid jurisdiction
        '401':
          description: Unauthorized
        '404':
          description: User not found
        '500':
          description: Internal server error
  /api/real-estate/jurisdictions/analytics:
    get:
      summary: Get Analytics
      description: /real-estate/jurisdictions/analytics endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/jurisdictions:
    get:
      summary: Get Jurisdictions
      description: /real-estate/jurisdictions endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/properties/{id}/jurisdiction:
    get:
      summary: Get Jurisdiction
      description: /real-estate/properties/{id}/jurisdiction endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/real-estate/properties/filter:
    post:
      summary: Create or submit Filter
      description: /real-estate/properties/filter endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/properties:
    get:
      summary: Get Properties
      description: /real-estate/properties endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Properties
      description: /real-estate/properties endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/realtor/leads:
    get:
      summary: Get Leads
      description: /real-estate/realtor/leads endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Leads
      description: /real-estate/realtor/leads endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/realtor/listings:
    get:
      summary: Get Listings
      description: /real-estate/realtor/listings endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Listings
      description: /real-estate/realtor/listings endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/realtor/stats:
    get:
      summary: Get Stats
      description: /real-estate/realtor/stats endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/real-estate/stats:
    get:
      summary: Get Stats
      description: /real-estate/stats endpoint.
      tags:
        - Real-Estate
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /reconciliation/dashboard:
    get:
      summary: Get reconciliation dashboard
      description: >-
        Returns reconciliation dashboard data (recent sessions, stats). Query
        params accountId, days.
      tags:
        - reconciliation
      parameters:
        - in: query
          name: accountId
          schema:
            type: string
        - in: query
          name: days
          schema:
            type: integer
      responses:
        '200':
          description: Dashboard data
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/reconciliation/match:
    get:
      summary: Get Match
      description: /reconciliation/match endpoint.
      tags:
        - Reconciliation
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Match
      description: /reconciliation/match endpoint.
      tags:
        - Reconciliation
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/reconciliation/matches/{matchId}:
    patch:
      summary: Update resource
      description: /reconciliation/matches/{matchId} endpoint.
      tags:
        - Reconciliation
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/reconciliation/rules:
    get:
      summary: Get Rules
      description: /reconciliation/rules endpoint.
      tags:
        - Reconciliation
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Rules
      description: /reconciliation/rules endpoint.
      tags:
        - Reconciliation
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/reconciliation/sessions:
    get:
      summary: Get Sessions
      description: /reconciliation/sessions endpoint.
      tags:
        - Reconciliation
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Sessions
      description: /reconciliation/sessions endpoint.
      tags:
        - Reconciliation
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /reconciliation/statement-transactions/{sessionId}:
    get:
      summary: Get statement transactions for a reconciliation session
      description: >-
        Returns statement transactions for the given session. Session must
        belong to the authenticated user.
      tags:
        - reconciliation
      parameters:
        - in: path
          name: sessionId
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Statement transactions array
        '401':
          description: Unauthorized
        '404':
          description: Session not found
        '500':
          description: Internal server error
  /api/remittances/{id}:
    patch:
      summary: Update a remittance
      description: Updates remittance status (typically from webhook or manual update)
      tags:
        - Remittances
      security:
        - BearerAuth: []
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                status:
                  type: string
                  enum:
                    - pending
                    - initiated
                    - completed
                    - cancelled
                recipientName:
                  type: string
                metadata:
                  type: object
      responses:
        '200':
          description: Remittance updated successfully
        '401':
          description: Unauthorized
        '404':
          description: Remittance not found
  /api/remittances/providers:
    get:
      summary: Get remittance provider status
      description: Returns status and configuration of all remittance providers
      tags:
        - Remittances
      security:
        - BearerAuth: []
      responses:
        '200':
          description: Provider status retrieved successfully
        '401':
          description: Unauthorized
  /api/remittances:
    post:
      summary: Create a new remittance
      description: Creates a new remittance record and generates Sendwave referral URL
      tags:
        - Remittances
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - amount
                - destinationCountry
              properties:
                amount:
                  type: number
                  example: 500
                currency:
                  type: string
                  default: USD
                destinationCountry:
                  type: string
                  enum:
                    - CO
                    - EC
                    - DO
                    - MX
                    - GT
                  example: CO
                recipientName:
                  type: string
                  example: Juan Perez
      responses:
        '201':
          description: Remittance created successfully
        '400':
          description: Validation error
        '401':
          description: Unauthorized
    get:
      summary: Get list of remittances
      description: Retrieves a paginated list of remittances with optional filtering
      tags:
        - Remittances
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: page
          schema:
            type: integer
            default: 1
        - in: query
          name: limit
          schema:
            type: integer
            default: 10
        - in: query
          name: status
          schema:
            type: string
            enum:
              - pending
              - initiated
              - completed
              - cancelled
        - in: query
          name: destinationCountry
          schema:
            type: string
            length: 2
      responses:
        '200':
          description: Remittances retrieved successfully
        '401':
          description: Unauthorized
  /reports/{id}/export:
    post:
      summary: Export report
      description: >-
        Exports a report by ID in the requested format (pdf, csv, excel, json).
        Body may include format, includeCharts, includeData. Requires
        authentication.
      tags:
        - reports
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Report ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                format:
                  type: string
                  enum:
                    - pdf
                    - csv
                    - excel
                    - json
                  default: pdf
                includeCharts:
                  type: boolean
                  default: true
                includeData:
                  type: boolean
                  default: true
      responses:
        '200':
          description: Export file or URL
        '400':
          description: Invalid JSON or validation error
        '401':
          description: Unauthorized
        '404':
          description: Report not found
        '500':
          description: Internal server error
  /api/reports/{id}/history:
    get:
      summary: Get report execution history
      description: Returns the execution history for a report (e.g. last 10 runs).
      tags:
        - Reports
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Report ID
      responses:
        '200':
          description: List of execution history entries
        '400':
          description: Invalid report ID
        '401':
          description: Unauthorized
  /reports/{id}:
    get:
      summary: Get report by ID
      description: Returns a single report by ID for the authenticated user.
      tags:
        - reports
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Report ID
      responses:
        '200':
          description: success
          data (report): null
          requestId: null
        '400':
          description: Invalid report ID
        '401':
          description: Unauthorized
        '404':
          description: Report not found
        '500':
          description: Internal server error
    patch:
      summary: Update report
      description: >-
        Updates an existing report. Body may include name, description, config,
        schedule. Requires authentication.
      tags:
        - reports
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                description:
                  type: string
                config:
                  type: object
                schedule:
                  type: object
      responses:
        '200':
          description: Updated report
        '400':
          description: Invalid report ID or validation error
        '401':
          description: Unauthorized
        '404':
          description: Report not found
        '500':
          description: Internal server error
    delete:
      summary: Delete report
      description: Deletes a report for the authenticated user.
      tags:
        - reports
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
        '400':
          description: Invalid report ID
        '401':
          description: Unauthorized
        '404':
          description: Report not found
        '500':
          description: Internal server error
  /api/reports/{id}/run:
    post:
      summary: Run report
      description: Executes a report and returns the result data and execution time.
      tags:
        - Reports
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Report ID
      responses:
        '200':
          description: Report result (data, reportId, executionTime)
        '400':
          description: Invalid report ID
        '401':
          description: Unauthorized
  /api/reports/{id}/share:
    post:
      summary: Share report
      description: Generates a share URL and optional password/expiration for a report.
      tags:
        - Reports
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Report ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                expiresIn:
                  type: number
                  description: Days until link expires
                password:
                  type: string
                allowDownload:
                  type: boolean
                  default: true
      responses:
        '200':
          description: Share URL and token returned
        '401':
          description: Unauthorized
        '404':
          description: Report not found
  /api/reports/ai-insights/settings:
    get:
      summary: Get AI insights settings
      description: >-
        Returns the user's AI insights configuration for reports (enabled,
        depth, types, provider).
      tags:
        - Reports
      responses:
        '200':
          description: AI insights config (enabled, depth, types, provider)
        '401':
          description: Unauthorized
    post:
      summary: Update AI insights settings
      description: Saves AI insights configuration (enabled, depth, types, provider).
      tags:
        - Reports
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                enabled:
                  type: boolean
                  default: true
                depth:
                  type: string
                  enum:
                    - basic
                    - standard
                    - deep
                  default: standard
                types:
                  type: array
                  items:
                    type: string
                  default:
                    - trends
                    - anomalies
                    - forecasts
                provider:
                  type: string
                  enum:
                    - auto
                    - openai
                    - claude
                    - google
                  default: auto
      responses:
        '200':
          description: Config saved
        '400':
          description: Invalid configuration
        '401':
          description: Unauthorized
  /api/reports/create:
    post:
      summary: Create report
      description: >-
        Creates a new report with optional save-as-template. Requires active
        organization.
      tags:
        - Reports
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
              properties:
                name:
                  type: string
                description:
                  type: string
                type:
                  type: string
                  enum:
                    - financial
                    - sales
                    - inventory
                    - customers
                    - analytics
                  default: financial
                format:
                  type: string
                  enum:
                    - pdf
                    - excel
                    - csv
                    - json
                  default: pdf
                saveAsTemplate:
                  type: boolean
                  default: false
                templateName:
                  type: string
      responses:
        '201':
          description: Report created
        '400':
          description: Invalid body or organization ID required
        '401':
          description: Unauthorized
  /api/reports:
    get:
      summary: Get list of reports
      description: >-
        Retrieves a paginated list of financial reports with optional filtering
        by type and favorites
      tags:
        - Analytics
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: type
          schema:
            type: string
          description: Filter reports by type
        - in: query
          name: isFavorite
          schema:
            type: boolean
          description: Return only favorite reports
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
          description: Maximum number of reports to return
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
          description: Number of reports to skip
      responses:
        '200':
          description: Reports retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: report_123
                        name:
                          type: string
                          example: Monthly Revenue Report
                        type:
                          type: string
                        isFavorite:
                          type: boolean
                        createdAt:
                          type: string
                          format: date-time
                  total:
                    type: integer
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/reports/schedule:
    get:
      summary: List report schedules
      description: Returns all report schedules for the current user.
      tags:
        - Reports
      responses:
        '200':
          description: List of report schedules
        '401':
          description: Unauthorized
    post:
      summary: Create or update report schedule
      description: >-
        Creates or updates a scheduled report (frequency, time, recipients,
        format).
      tags:
        - Reports
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - reportId
                - enabled
                - frequency
                - time
              properties:
                reportId:
                  type: string
                enabled:
                  type: boolean
                frequency:
                  type: string
                  enum:
                    - daily
                    - weekly
                    - monthly
                    - custom
                dayOfWeek:
                  type: string
                dayOfMonth:
                  type: string
                time:
                  type: string
                  pattern: ^([0-1]?[0-9]|2[0-3]):[0-5][0-9]$
                timezone:
                  type: string
                  default: UTC
                format:
                  type: string
                  enum:
                    - pdf
                    - excel
                    - csv
                  default: pdf
                recipients:
                  type: array
                  items:
                    type: string
                    format: email
      responses:
        '200':
          description: Schedule updated
        '201':
          description: Schedule created
        '401':
          description: Unauthorized
        '404':
          description: Report not found
  /api/reports/settings:
    post:
      summary: Update report settings
      description: Saves report-related user preferences (stored in user preferences).
      tags:
        - Reports
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                settings:
                  type: object
      responses:
        '200':
          description: Settings updated
        '401':
          description: Unauthorized
  /api/reports/templates:
    get:
      summary: List report templates
      description: Returns all report templates, optionally filtered by category.
      tags:
        - Reports
      parameters:
        - in: query
          name: category
          schema:
            type: string
          description: Filter by category
      responses:
        '200':
          description: List of report templates
        '401':
          description: Unauthorized
    post:
      summary: Create template or report from template
      description: >-
        Creates a new template or creates a report from an existing template
        (templateId).
      tags:
        - Reports
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                templateId:
                  type: number
                customizations:
                  type: object
                name:
                  type: string
                category:
                  type: string
                description:
                  type: string
                type:
                  type: string
                config:
                  type: object
      responses:
        '201':
          description: Template or report created
        '400':
          description: Invalid request (e.g. name/category required)
        '401':
          description: Unauthorized
  /api/research:
    post:
      summary: Create or submit Research
      description: /research endpoint.
      tags:
        - Research
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/search/content/popular:
    get:
      summary: Get Popular
      description: /search/content/popular endpoint.
      tags:
        - Search
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/search/content:
    get:
      summary: Get Content
      description: /search/content endpoint.
      tags:
        - Search
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Content
      description: /search/content endpoint.
      tags:
        - Search
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/search:
    get:
      summary: Search across the platform
      description: >-
        Performs a unified search across invoices, transactions, clients, pages,
        and reports
      tags:
        - Analytics
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: q
          required: true
          schema:
            type: string
          description: Search query string
        - in: query
          name: type
          schema:
            type: string
            enum:
              - page
              - transaction
              - invoice
              - client
              - report
              - setting
          description: Filter results by type
        - in: query
          name: limit
          schema:
            type: integer
            default: 20
          description: Maximum number of results to return
      responses:
        '200':
          description: Search results retrieved successfully
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: string
                    title:
                      type: string
                    description:
                      type: string
                    type:
                      type: string
                      enum:
                        - page
                        - transaction
                        - invoice
                        - client
                        - report
                        - setting
                    href:
                      type: string
                    icon:
                      type: string
                    metadata:
                      type: object
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/search/settings:
    get:
      summary: Get Settings
      description: /search/settings endpoint.
      tags:
        - Search
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Settings
      description: /search/settings endpoint.
      tags:
        - Search
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/security/audit-logs:
    get:
      summary: Get Audit Logs
      description: /security/audit-logs endpoint.
      tags:
        - Security
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/security/audit-statistics:
    get:
      summary: Get Audit Statistics
      description: /security/audit-statistics endpoint.
      tags:
        - Security
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/security/events/{id}/resolve:
    post:
      summary: Create or submit Resolve
      description: /security/events/{id}/resolve endpoint.
      tags:
        - Security
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/security/events:
    get:
      summary: Get Events
      description: /security/events endpoint.
      tags:
        - Security
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/security/mfa:
    get:
      summary: Get Mfa
      description: /security/mfa endpoint.
      tags:
        - Security
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/security/mfa/setup:
    post:
      summary: Create or submit Setup
      description: /security/mfa/setup endpoint.
      tags:
        - Security
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/security/mfa/verify:
    post:
      summary: Create or submit Verify
      description: /security/mfa/verify endpoint.
      tags:
        - Security
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/security/overview:
    get:
      summary: Get Overview
      description: /security/overview endpoint.
      tags:
        - Security
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/sentry/sync-issues:
    get:
      summary: Get Sync Issues
      description: /sentry/sync-issues endpoint.
      tags:
        - Sentry
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Sync Issues
      description: /sentry/sync-issues endpoint.
      tags:
        - Sentry
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /settings/billing/history:
    get:
      summary: Get billing history
      description: >-
        Returns the authenticated user billing history (invoices, payments).
        Query params limit (default 20), offset (default 0). Requires
        authentication.
      tags:
        - settings
        - billing
      parameters:
        - in: query
          name: limit
          schema:
            type: integer
            default: 20
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: Billing history array
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/settings/billing/payment-methods:
    get:
      summary: List payment methods
      description: >-
        Returns all payment methods for the authenticated user (cards, etc.).
        Metadata only; no full card data.
      tags:
        - Settings
        - Billing
      responses:
        '200':
          description: >-
            List of payment methods (id, type, last4, brand, expiry, isDefault,
            status)
        '401':
          description: Unauthorized
    post:
      summary: Add payment method
      description: >-
        Adds a new payment method. Requires stripePaymentMethodId; may fetch
        details from Stripe. Optional isDefault.
      tags:
        - Settings
        - Billing
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - stripePaymentMethodId
              properties:
                stripePaymentMethodId:
                  type: string
                type:
                  type: string
                  default: card
                last4:
                  type: string
                brand:
                  type: string
                expiryMonth:
                  type: integer
                expiryYear:
                  type: integer
                isDefault:
                  type: boolean
                  default: false
                metadata:
                  type: object
      responses:
        '200':
          description: Created payment method
        '400':
          description: Stripe payment method ID required or invalid JSON
        '401':
          description: Unauthorized
  /settings/billing/plans:
    get:
      summary: Get subscription plans
      description: >-
        Returns all active subscription plans (public; no auth required). Used
        for pricing display.
      tags:
        - settings
        - billing
      responses:
        '200':
          description: Plans array with id
          name: null
          priceMonthly: null
          priceYearly: null
          features: null
          limits: null
        '500':
          description: Internal server error
  /settings/billing/subscription:
    get:
      summary: Get current subscription
      description: >-
        Returns the authenticated user's current subscription (plan, status,
        Stripe sync). Resilient to missing billing tables.
      tags:
        - settings
        - billing
      responses:
        '200':
          description: Current subscription and plan details
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create or update subscription
      description: >-
        Creates or updates user subscription (e.g. plan change, Stripe
        checkout). Request body may include planId, stripePriceId, etc.
      tags:
        - settings
        - billing
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                planId:
                  type: string
                stripePriceId:
                  type: string
      responses:
        '200':
          description: Updated subscription
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /settings/notifications:
    get:
      summary: Get notification preferences
      description: >-
        Returns the authenticated user notification preferences (email, push,
        in-app, slack). Requires authentication.
      tags:
        - settings
        - notifications
      responses:
        '200':
          description: Notification preferences object
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    put:
      summary: Update notification preferences
      description: >-
        Updates the authenticated user notification preferences. Body may
        include emailInvoices, emailExpenses, pushRealtime, etc. Requires
        authentication.
      tags:
        - settings
        - notifications
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                emailInvoices:
                  type: boolean
                emailExpenses:
                  type: boolean
                pushRealtime:
                  type: boolean
                slackEnabled:
                  type: boolean
      responses:
        '200':
          description: Updated preferences
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/settings/preferences/notifications:
    get:
      summary: Get notification preferences
      description: >-
        Returns the authenticated user notification preferences (email, push,
        in-app channels).
      tags:
        - Settings
      responses:
        '200':
          description: Notification preferences object
        '401':
          description: Unauthorized
    put:
      summary: Update notification preferences
      description: >-
        Updates notification preference fields (emailInvoices, emailPayments,
        pushInvoices, etc.).
      tags:
        - Settings
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                emailInvoices:
                  type: boolean
                emailPayments:
                  type: boolean
                emailReports:
                  type: boolean
                pushInvoices:
                  type: boolean
                inAppInvoices:
                  type: boolean
      responses:
        '200':
          description: Updated notification preferences
        '401':
          description: Unauthorized
  /api/settings/preferences/privacy:
    get:
      summary: Get privacy settings
      description: >-
        Returns the authenticated user privacy settings (analytics, error
        reporting, data retention, sharing, etc.).
      tags:
        - Settings
      responses:
        '200':
          description: Privacy settings object
        '401':
          description: Unauthorized
    put:
      summary: Update privacy settings
      description: >-
        Updates privacy and data control preferences (analyticsTracking,
        errorReporting, dataRetentionPeriod, etc.).
      tags:
        - Settings
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                analyticsTracking:
                  type: boolean
                errorReporting:
                  type: boolean
                performanceMonitoring:
                  type: boolean
                usageStatistics:
                  type: boolean
                dataRetentionPeriod:
                  type: string
                allowPersonalization:
                  type: boolean
      responses:
        '200':
          description: Updated privacy settings
        '401':
          description: Unauthorized
  /api/settings/preferences:
    get:
      summary: Get user preferences
      description: >-
        Returns the authenticated user preferences (theme, language, timezone,
        formats, dashboard, etc.). Defaults if none exist.
      tags:
        - Settings
      responses:
        '200':
          description: Preferences object
        '401':
          description: Unauthorized
    put:
      summary: Update user preferences
      description: >-
        Updates allowed preference fields (theme, language, timezone,
        dateFormat, timeFormat, currency, defaultDashboard, sidebarCollapsed,
        etc.).
      tags:
        - Settings
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                theme:
                  type: string
                language:
                  type: string
                timezone:
                  type: string
                dateFormat:
                  type: string
                timeFormat:
                  type: string
                currency:
                  type: string
                currencySymbol:
                  type: string
                numberFormat:
                  type: string
                defaultDashboard:
                  type: string
                dashboardLayout:
                  type: object
                sidebarCollapsed:
                  type: boolean
                enabledFeatures:
                  type: array
                betaFeatures:
                  type: boolean
      responses:
        '200':
          description: Updated preferences
        '400':
          description: No valid fields to update or invalid JSON
        '401':
          description: Unauthorized
  /api/settings/security/api-keys/{id}/regenerate:
    post:
      summary: Regenerate API key
      description: >-
        Generates a new API key with the same settings and revokes the old one.
        Full key returned only once. User must own the key.
      tags:
        - Settings
        - Security
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: API key ID
      responses:
        '200':
          description: New key metadata and apiKey (full key, only on regeneration)
        '401':
          description: Unauthorized
        '404':
          description: API key not found
  /api/settings/security/api-keys/{id}:
    put:
      summary: Update API key
      description: >-
        Updates an existing API key (name, description, status, scopes,
        expiresAt, rate limits). User must own the key.
      tags:
        - Settings
        - Security
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: API key ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                description:
                  type: string
                status:
                  type: string
                scopes:
                  type: array
                  items:
                    type: string
                expiresAt:
                  type: string
                  format: date-time
                rateLimitPerMinute:
                  type: integer
                rateLimitPerHour:
                  type: integer
      responses:
        '200':
          description: Updated key metadata
        '400':
          description: Invalid JSON
        '401':
          description: Unauthorized
        '404':
          description: API key not found
    delete:
      summary: Revoke API key
      description: >-
        Soft-deletes the API key by setting status to revoked. User must own the
        key.
      tags:
        - Settings
        - Security
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: API key ID
      responses:
        '200':
          description: API key revoked successfully
        '401':
          description: Unauthorized
        '404':
          description: API key not found
  /api/settings/security/api-keys/{id}/usage:
    get:
      summary: Get API key usage
      description: Returns usage statistics for a specific API key. User must own the key.
      tags:
        - Settings
        - Security
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: API key ID
      responses:
        '200':
          description: Usage stats (success, usage)
        '401':
          description: Unauthorized
        '404':
          description: API key not found
  /api/settings/security/api-keys:
    get:
      summary: List API keys
      description: >-
        Returns all API keys for the authenticated user (metadata only; full key
        shown only on creation).
      tags:
        - Settings
        - Security
      responses:
        '200':
          description: >-
            List of keys (id, name, description, type, scopes, status,
            lastUsedAt, expiresAt, usageCount, etc.)
        '401':
          description: Unauthorized
    post:
      summary: Create API key
      description: >-
        Creates a new API key. The full key is returned only once on creation;
        store it securely.
      tags:
        - Settings
        - Security
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
              properties:
                name:
                  type: string
                description:
                  type: string
                type:
                  type: string
                  default: production
                scopes:
                  type: array
                  items:
                    type: string
                  default:
                    - read
                    - write
                expiresAt:
                  type: string
                  format: date-time
                rateLimitPerMinute:
                  type: integer
                  default: 1000
                rateLimitPerHour:
                  type: integer
                  default: 10000
      responses:
        '200':
          description: Key metadata and apiKey (full key, only on creation)
        '400':
          description: Name is required or invalid JSON
        '401':
          description: Unauthorized
  /settings/security/sessions:
    get:
      summary: List active sessions
      description: >-
        Returns the authenticated user's active sessions (Clerk + DB). May
        include IP/location. Requires authentication.
      tags:
        - settings
        - security
      responses:
        '200':
          description: List of sessions
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    delete:
      summary: Revoke session(s)
      description: >-
        Revokes one or more sessions. Body may include sessionId or sessionIds.
        Requires authentication.
      tags:
        - settings
        - security
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                sessionId:
                  type: string
                sessionIds:
                  type: array
                  items:
                    type: string
      responses:
        '200':
          description: Sessions revoked
        '400':
          description: Missing sessionId/sessionIds
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/settings/white-label:
    get:
      summary: Get white-label branding
      description: >-
        Returns branding configuration for the current workspace or
        organization. Optional query workspaceId, organizationId.
      tags:
        - Settings
      parameters:
        - in: query
          name: workspaceId
          schema:
            type: string
        - in: query
          name: organizationId
          schema:
            type: string
      responses:
        '200':
          description: Branding configuration (logo, colors, name, etc.)
        '401':
          description: Unauthorized
        '403':
          description: Workspace not found or access denied
    put:
      summary: Update white-label branding
      description: >-
        Updates branding for a workspace. Body workspaceId, branding (logo,
        primaryColor, name, etc.). Requires authentication.
      tags:
        - Settings
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - workspaceId
                - branding
              properties:
                workspaceId:
                  type: string
                branding:
                  type: object
                  properties:
                    logoUrl:
                      type: string
                    primaryColor:
                      type: string
                    name:
                      type: string
      responses:
        '200':
          description: Updated branding
        '401':
          description: Unauthorized
        '403':
          description: Access denied
  /api/support/category/{slug}:
    get:
      summary: Get resource
      description: /support/category/{slug} endpoint.
      tags:
        - Support
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/support/create-from-error:
    post:
      summary: Create or submit Create From Error
      description: /support/create-from-error endpoint.
      tags:
        - Support
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/support/public:
    post:
      summary: Create or submit Public
      description: /support/public endpoint.
      tags:
        - Support
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/support/search:
    get:
      summary: Get Search
      description: /support/search endpoint.
      tags:
        - Support
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /sync/dashboard-data:
    get:
      summary: Sync or get dashboard data
      description: >-
        Sync dashboard data (accounts, transactions) or return cached data. Use
        ?sync=true to force full sync.
      tags:
        - sync
      parameters:
        - in: query
          name: sync
          schema:
            type: string
            enum:
              - true
              - false
      responses:
        '200':
          description: Sync result or cached dashboard data
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/tax-intake/documents:
    get:
      summary: Get Documents
      description: /tax-intake/documents endpoint.
      tags:
        - Tax-Intake
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Documents
      description: /tax-intake/documents endpoint.
      tags:
        - Tax-Intake
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/tax-intake/engagements/{id}/documents:
    post:
      summary: Create or submit Documents
      description: /tax-intake/engagements/{id}/documents endpoint.
      tags:
        - Tax-Intake
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/tax-intake/engagements/{id}/engagement-letter:
    post:
      summary: Create or submit Engagement Letter
      description: /tax-intake/engagements/{id}/engagement-letter endpoint.
      tags:
        - Tax-Intake
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /tax-intake/engagements:
    post:
      summary: Create tax engagement and intake link
      description: >-
        Creates a tax engagement and returns an intake URL. Body clientId OR
        (email, name?) plus taxYear, optional channel (email, whatsapp, sms,
        other).
      tags:
        - tax-intake
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - taxYear
              properties:
                clientId:
                  type: integer
                email:
                  type: string
                phone:
                  type: string
                name:
                  type: string
                taxYear:
                  type: integer
                  minimum: 2020
                  maximum: 2030
                channel:
                  type: string
                  enum:
                    - email
                    - whatsapp
                    - sms
                    - other
      responses:
        '200':
          description: engagementId
          intakeUrl: null
          token: null
        '400':
          description: Invalid JSON or validation error (clientId or email required)
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/tax-intake/link/{token}:
    get:
      summary: Get resource
      description: /tax-intake/link/{token} endpoint.
      tags:
        - Tax-Intake
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/tax-intake/link:
    get:
      summary: Get Link
      description: /tax-intake/link endpoint.
      tags:
        - Tax-Intake
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/tax-intake/portal/engagement/{engagementId}:
    get:
      summary: Get resource
      description: /tax-intake/portal/engagement/{engagementId} endpoint.
      tags:
        - Tax-Intake
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/tax-intake/start:
    post:
      summary: Create or submit Start
      description: /tax-intake/start endpoint.
      tags:
        - Tax-Intake
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /tax-intake/verify:
    post:
      summary: Verify tax intake (public)
      description: >-
        Consumes intake token, updates client info, sets used_at and status,
        sets portal cookie, returns redirect URL. Body requires token; optional
        name, dob, ssn, address, city, state, zipCode, country. No auth required
        (public).
      tags:
        - tax-intake
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - token
              properties:
                token:
                  type: string
                name:
                  type: string
                dob:
                  type: string
                ssn:
                  type: string
                address:
                  type: string
                city:
                  type: string
                state:
                  type: string
                zipCode:
                  type: string
                country:
                  type: string
      responses:
        '200':
          description: redirectUrl and success
        '400':
          description: Invalid JSON or validation failed
        '404':
          description: Intake link not found or expired
        '500':
          description: Internal server error
  /api/tax/deductions/{id}:
    patch:
      summary: Update resource
      description: /tax/deductions/{id} endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /tax/deductions/{id} endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/tax/deductions:
    get:
      summary: Get Deductions
      description: /tax/deductions endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Deductions
      description: /tax/deductions endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/tax/direct-file/exports/{id}:
    delete:
      summary: Delete resource
      description: /tax/direct-file/exports/{id} endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/tax/direct-file/exports:
    get:
      summary: Get Exports
      description: /tax/direct-file/exports endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Exports
      description: /tax/direct-file/exports endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/tax/documents/{id}:
    delete:
      summary: Delete resource
      description: /tax/documents/{id} endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/tax/documents:
    get:
      summary: Get Documents
      description: /tax/documents endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Documents
      description: /tax/documents endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/tax/export:
    get:
      summary: Get Export
      description: /tax/export endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/tax/obligations/{id}/payment:
    post:
      summary: Create or submit Payment
      description: /tax/obligations/{id}/payment endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/tax/obligations/{id}:
    get:
      summary: Get resource
      description: /tax/obligations/{id} endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /tax/obligations/{id} endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /tax/obligations/{id} endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/tax/obligations:
    get:
      summary: Get Obligations
      description: /tax/obligations endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Obligations
      description: /tax/obligations endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/tax/summary:
    get:
      summary: Get Summary
      description: /tax/summary endpoint.
      tags:
        - Tax
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test-dashboard-activity:
    get:
      summary: Get Test Dashboard Activity
      description: /test-dashboard-activity endpoint.
      tags:
        - Test-Dashboard-Activity
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test-dashboard-insights:
    get:
      summary: Get Test Dashboard Insights
      description: /test-dashboard-insights endpoint.
      tags:
        - Test-Dashboard-Insights
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test-dashboard-overview:
    get:
      summary: Get Test Dashboard Overview
      description: /test-dashboard-overview endpoint.
      tags:
        - Test-Dashboard-Overview
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test-dashboard/ai-insights:
    get:
      summary: Get Ai Insights
      description: /test-dashboard/ai-insights endpoint.
      tags:
        - Test-Dashboard
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test-dashboard/overview:
    get:
      summary: Get Overview
      description: /test-dashboard/overview endpoint.
      tags:
        - Test-Dashboard
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test-dashboard/recent-activity:
    get:
      summary: Get Recent Activity
      description: /test-dashboard/recent-activity endpoint.
      tags:
        - Test-Dashboard
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test-db:
    get:
      summary: Get Test Db
      description: /test-db endpoint.
      tags:
        - Test-Db
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test-error:
    get:
      summary: Get Test Error
      description: /test-error endpoint.
      tags:
        - Test-Error
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test-glitchtip:
    get:
      summary: Get Test Glitchtip
      description: /test-glitchtip endpoint.
      tags:
        - Test-Glitchtip
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test-invoice-service:
    get:
      summary: Get Test Invoice Service
      description: /test-invoice-service endpoint.
      tags:
        - Test-Invoice-Service
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test-minimal-final:
    get:
      summary: Get Test Minimal Final
      description: /test-minimal-final endpoint.
      tags:
        - Test-Minimal-Final
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/test:
    get:
      summary: Get Test
      description: /test endpoint.
      tags:
        - Test
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/time-entries/{id}:
    get:
      summary: Get resource
      description: /time-entries/{id} endpoint.
      tags:
        - Time-Entries
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /time-entries/{id} endpoint.
      tags:
        - Time-Entries
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /time-entries/{id} endpoint.
      tags:
        - Time-Entries
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/time-entries/{id}/stop:
    post:
      summary: Create or submit Stop
      description: /time-entries/{id}/stop endpoint.
      tags:
        - Time-Entries
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/time-entries:
    get:
      summary: Get Time Entries
      description: /time-entries endpoint.
      tags:
        - Time-Entries
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Time Entries
      description: /time-entries endpoint.
      tags:
        - Time-Entries
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/time-entries/stats:
    get:
      summary: Get Stats
      description: /time-entries/stats endpoint.
      tags:
        - Time-Entries
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/timesheets/audio:
    get:
      summary: Get Audio
      description: /timesheets/audio endpoint.
      tags:
        - Timesheets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    put:
      summary: Update Audio
      description: /timesheets/audio endpoint.
      tags:
        - Timesheets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/timesheets/audio/transcribe:
    post:
      summary: Create or submit Transcribe
      description: /timesheets/audio/transcribe endpoint.
      tags:
        - Timesheets
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /tours/analytics:
    get:
      summary: Get tour analytics
      description: >-
        Returns tour analytics. Optional tourId (specific tour or all), period
        (day, week, month, all), startDate, endDate.
      tags:
        - tours
        - analytics
      parameters:
        - in: query
          name: tourId
          schema:
            type: string
          description: Specific tour ID (omit for all tours).
        - in: query
          name: period
          schema:
            type: string
            enum:
              - day
              - week
              - month
              - all
            default: all
        - in: query
          name: startDate
          schema:
            type: string
            format: date
        - in: query
          name: endDate
          schema:
            type: string
            format: date
      responses:
        '200':
          description: Analytics object in data
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/tours/check:
    get:
      summary: Get Check
      description: /tours/check endpoint.
      tags:
        - Tours
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/tours/complete:
    post:
      summary: Create or submit Complete
      description: /tours/complete endpoint.
      tags:
        - Tours
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/tours:
    get:
      summary: Get Tours
      description: /tours endpoint.
      tags:
        - Tours
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Tours
      description: /tours endpoint.
      tags:
        - Tours
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/training/paths-with-progress:
    get:
      summary: Get Paths With Progress
      description: /training/paths-with-progress endpoint.
      tags:
        - Training
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/training/paths:
    get:
      summary: Get Paths
      description: /training/paths endpoint.
      tags:
        - Training
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/training/prepare-dataset:
    post:
      summary: Create or submit Prepare Dataset
      description: /training/prepare-dataset endpoint.
      tags:
        - Training
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/training/programs-with-progress:
    get:
      summary: Get Programs With Progress
      description: /training/programs-with-progress endpoint.
      tags:
        - Training
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/training/programs/{id}:
    get:
      summary: Get resource
      description: /training/programs/{id} endpoint.
      tags:
        - Training
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/training/programs:
    get:
      summary: Get Programs
      description: /training/programs endpoint.
      tags:
        - Training
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/training/progress:
    get:
      summary: Get Progress
      description: /training/progress endpoint.
      tags:
        - Training
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Progress
      description: /training/progress endpoint.
      tags:
        - Training
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/training/stats:
    get:
      summary: Get Stats
      description: /training/stats endpoint.
      tags:
        - Training
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/transactions/{id}:
    get:
      summary: Get resource
      description: /transactions/{id} endpoint.
      tags:
        - Transactions
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /transactions/{id} endpoint.
      tags:
        - Transactions
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /transactions/{id} endpoint.
      tags:
        - Transactions
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/transactions/jurisdiction/breakdown:
    get:
      summary: Get Breakdown
      description: /transactions/jurisdiction/breakdown endpoint.
      tags:
        - Transactions
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/transactions/jurisdiction:
    get:
      summary: Get Jurisdiction
      description: /transactions/jurisdiction endpoint.
      tags:
        - Transactions
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/transactions:
    get:
      summary: Get list of transactions
      description: >-
        Retrieves a paginated list of financial transactions with filtering by
        type, status, category, and date range
      tags:
        - Financial
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: type
          schema:
            type: string
            enum:
              - income
              - expense
              - transfer
              - payment
          description: Filter transactions by type
        - in: query
          name: status
          schema:
            type: string
          description: Filter transactions by status
        - in: query
          name: category
          schema:
            type: string
          description: Filter transactions by category
        - in: query
          name: startDate
          schema:
            type: string
            format: date
          description: Start date for filtering (YYYY-MM-DD)
        - in: query
          name: endDate
          schema:
            type: string
            format: date
          description: End date for filtering (YYYY-MM-DD)
        - in: query
          name: search
          schema:
            type: string
          description: Search term for transaction description
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
          description: Maximum number of transactions to return
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
          description: Number of transactions to skip
      responses:
        '200':
          description: Transactions retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  transactions:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: trans_123
                        type:
                          type: string
                          enum:
                            - income
                            - expense
                            - transfer
                            - payment
                        amount:
                          type: number
                          example: 1250
                        currency:
                          type: string
                          example: USD
                        description:
                          type: string
                        category:
                          type: string
                        status:
                          type: string
                          enum:
                            - pending
                            - completed
                            - failed
                            - cancelled
                        transactionDate:
                          type: string
                          format: date-time
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Create a new transaction
      description: >-
        Creates a new financial transaction record (income, expense, transfer,
        or payment)
      tags:
        - Financial
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - type
                - amount
                - transactionDate
              properties:
                type:
                  type: string
                  enum:
                    - income
                    - expense
                    - transfer
                    - payment
                  example: expense
                amount:
                  type: number
                  example: 1250
                currency:
                  type: string
                  default: USD
                description:
                  type: string
                  example: Monthly subscription payment
                category:
                  type: string
                  example: Software
                paymentMethod:
                  type: string
                  example: credit_card
                referenceId:
                  type: string
                referenceType:
                  type: string
                accountId:
                  type: string
                transactionDate:
                  type: string
                  format: date-time
                notes:
                  type: string
                metadata:
                  type: object
      responses:
        '201':
          description: Transaction created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  transaction:
                    type: object
                    properties:
                      id:
                        type: string
                        example: trans_123
                      type:
                        type: string
                      amount:
                        type: number
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/transactions/stats:
    get:
      summary: Get Stats
      description: /transactions/stats endpoint.
      tags:
        - Transactions
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/ui-patterns:
    get:
      summary: Get Ui Patterns
      description: /ui-patterns endpoint.
      tags:
        - Ui-Patterns
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/unified-dashboard/metrics:
    get:
      summary: Get Metrics
      description: /unified-dashboard/metrics endpoint.
      tags:
        - Unified-Dashboard
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/unified-dashboard/widgets:
    get:
      summary: Get Widgets
      description: /unified-dashboard/widgets endpoint.
      tags:
        - Unified-Dashboard
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/uploadthing: {}
  /api/usage/check-plan:
    get:
      summary: Get Check Plan
      description: /usage/check-plan endpoint.
      tags:
        - Usage
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/usage/check:
    get:
      summary: Get Check
      description: /usage/check endpoint.
      tags:
        - Usage
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/usage/info:
    get:
      summary: Get Info
      description: /usage/info endpoint.
      tags:
        - Usage
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/usage/track:
    post:
      summary: Create or submit Track
      description: /usage/track endpoint.
      tags:
        - Usage
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/user/persona:
    get:
      summary: Get Persona
      description: /user/persona endpoint.
      tags:
        - User
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/v1/health:
    get:
      summary: Get Health
      description: /v1/health endpoint.
      tags:
        - V1
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/vendors:
    get:
      summary: Get list of vendors
      description: >-
        Retrieves a paginated list of vendors with optional filtering by status
        and category
      tags:
        - Financial
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: status
          schema:
            type: string
            enum:
              - active
              - inactive
              - suspended
              - blacklisted
          description: Filter vendors by status
        - in: query
          name: category
          schema:
            type: string
          description: Filter vendors by category
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
          description: Maximum number of vendors to return
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
          description: Number of vendors to skip
      responses:
        '200':
          description: Vendors retrieved successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  vendors:
                    type: array
                    items:
                      type: object
                      properties:
                        id:
                          type: string
                          example: vendor_123
                        name:
                          type: string
                          example: Acme Supplies Inc
                        email:
                          type: string
                          format: email
                        status:
                          type: string
                          enum:
                            - active
                            - inactive
                            - suspended
                            - blacklisted
                        paymentTerms:
                          type: string
                          example: Net 30
                  total:
                    type: integer
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Create a new vendor
      description: >-
        Creates a new vendor record with payment preferences and approval
        settings
      tags:
        - Financial
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
              properties:
                name:
                  type: string
                  example: Acme Supplies Inc
                email:
                  type: string
                  format: email
                  example: contact@acme.com
                phone:
                  type: string
                  example: +1-555-0123
                address:
                  type: string
                city:
                  type: string
                state:
                  type: string
                zipCode:
                  type: string
                taxId:
                  type: string
                  example: 12-3456789
                paymentTerms:
                  type: string
                  example: Net 30
                category:
                  type: string
                  example: supplier
                paymentMethods:
                  type: array
                  items:
                    type: string
                  example:
                    - check
                    - ach
                autoPay:
                  type: boolean
                  default: false
                approvalRequired:
                  type: boolean
                  default: true
                approvalThreshold:
                  type: number
                  default: 1000
      responses:
        '201':
          description: Vendor created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  vendor:
                    type: object
                    properties:
                      id:
                        type: string
                        example: vendor_123
                      name:
                        type: string
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /video-conferencing/integrations:
    get:
      summary: List video conferencing integrations
      description: >-
        Returns the authenticated user's video conferencing integrations (Zoom,
        Google Meet) and their status.
      tags:
        - video-conferencing
        - integrations
      responses:
        '200':
          description: List of integrations
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Connect video conferencing integration
      description: >-
        OAuth callback flow to connect a provider (zoom, google_meet). Body
        requires provider, code, clientId, clientSecret, redirectUri.
      tags:
        - video-conferencing
        - integrations
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - provider
                - code
                - clientId
                - redirectUri
              properties:
                provider:
                  type: string
                  enum:
                    - zoom
                    - google_meet
                code:
                  type: string
                clientId:
                  type: string
                clientSecret:
                  type: string
                redirectUri:
                  type: string
      responses:
        '200':
          description: Integration connected
        '400':
          description: Missing required fields
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/video-conferencing/meetings/{meetingId}/breakout-rooms:
    get:
      summary: Get Breakout Rooms
      description: /video-conferencing/meetings/{meetingId}/breakout-rooms endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Breakout Rooms
      description: /video-conferencing/meetings/{meetingId}/breakout-rooms endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/video-conferencing/meetings/{meetingId}/end:
    post:
      summary: Create or submit End
      description: /video-conferencing/meetings/{meetingId}/end endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/video-conferencing/meetings/{meetingId}/polls/{pollId}/vote:
    post:
      summary: Create or submit Vote
      description: /video-conferencing/meetings/{meetingId}/polls/{pollId}/vote endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/video-conferencing/meetings/{meetingId}/polls:
    get:
      summary: Get Polls
      description: /video-conferencing/meetings/{meetingId}/polls endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Polls
      description: /video-conferencing/meetings/{meetingId}/polls endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/video-conferencing/meetings/{meetingId}/screen-share:
    get:
      summary: Get Screen Share
      description: /video-conferencing/meetings/{meetingId}/screen-share endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Screen Share
      description: /video-conferencing/meetings/{meetingId}/screen-share endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    delete:
      summary: Delete Screen Share
      description: /video-conferencing/meetings/{meetingId}/screen-share endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/video-conferencing/meetings:
    get:
      summary: Get Meetings
      description: /video-conferencing/meetings endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Meetings
      description: /video-conferencing/meetings endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/video-conferencing/oauth/callback:
    post:
      summary: Create or submit Callback
      description: /video-conferencing/oauth/callback endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/video-conferencing/settings:
    get:
      summary: Get Settings
      description: /video-conferencing/settings endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    put:
      summary: Update Settings
      description: /video-conferencing/settings endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/video-conferencing/whiteboard:
    get:
      summary: Get Whiteboard
      description: /video-conferencing/whiteboard endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Whiteboard
      description: /video-conferencing/whiteboard endpoint.
      tags:
        - Video-Conferencing
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/webhooks/{id}/deliveries:
    get:
      summary: Get Deliveries
      description: /webhooks/{id}/deliveries endpoint.
      tags:
        - Webhooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/webhooks/{id}/retry:
    post:
      summary: Create or submit Retry
      description: /webhooks/{id}/retry endpoint.
      tags:
        - Webhooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/webhooks/{id}:
    get:
      summary: Get resource
      description: /webhooks/{id} endpoint.
      tags:
        - Webhooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    put:
      summary: Update resource
      description: /webhooks/{id} endpoint.
      tags:
        - Webhooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /webhooks/{id} endpoint.
      tags:
        - Webhooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/webhooks/{id}/test:
    post:
      summary: Create or submit Test
      description: /webhooks/{id}/test endpoint.
      tags:
        - Webhooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /webhooks/clerk:
    post:
      summary: Clerk webhook handler
      description: >-
        Handles Clerk webhook events (user created, updated, deleted,
        organization membership, etc.). Verifies Svix signature. Syncs users and
        organizations to DB.
      tags:
        - webhooks
        - auth
      parameters:
        - in: header
          name: svix-id
          schema:
            type: string
          description: Svix message ID
        - in: header
          name: svix-timestamp
          schema:
            type: string
        - in: header
          name: svix-signature
          required: true
          schema:
            type: string
          description: Svix webhook signature
      requestBody:
        content:
          application/json:
            schema:
              type: object
              description: Raw Clerk event payload
      responses:
        '200':
          description: Processed
        '400':
          description: Invalid payload or signature
        '500':
          description: Internal server error
  /webhooks/n8n:
    post:
      summary: n8n webhook callback
      description: >-
        Receives callbacks from n8n workflows (e.g. HTTP Request node). Body
        action (ping, trigger_notification, update_record, trigger_workflow,
        log_result), executionId, workflowId, payload, entityType, entityId,
        updates. Optional x-n8n-callback-secret or Bearer for auth.
      tags:
        - webhooks
      parameters:
        - in: header
          name: x-n8n-callback-secret
          schema:
            type: string
          description: N8N_WEBHOOK_CALLBACK_SECRET env value
        - in: header
          name: authorization
          schema:
            type: string
          description: Bearer token (alternative to x-n8n-callback-secret)
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                action:
                  type: string
                  enum:
                    - ping
                    - trigger_notification
                    - update_record
                    - trigger_workflow
                    - log_result
                executionId:
                  type: string
                workflowId:
                  type: string
                payload:
                  type: object
                entityType:
                  type: string
                entityId:
                  type: string
                updates:
                  type: object
      responses:
        '200':
          description: Processed
        '401':
          description: Unauthorized (invalid or missing secret)
        '500':
          description: Internal server error
  /api/webhooks:
    get:
      summary: Get list of webhooks
      description: >-
        Retrieves a paginated list of webhook endpoints configured for the
        authenticated user
      tags:
        - Integrations
      security:
        - BearerAuth: []
      parameters:
        - in: query
          name: search
          schema:
            type: string
          description: Search term to filter webhooks by name or URL
        - in: query
          name: status
          schema:
            type: string
            enum:
              - active
              - inactive
          description: Filter webhooks by status
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
          description: Maximum number of webhooks to return
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
          description: Number of webhooks to skip
      responses:
        '200':
          description: Webhooks retrieved successfully
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: string
                      example: webhook_123
                    name:
                      type: string
                      example: Invoice Paid Webhook
                    url:
                      type: string
                      format: uri
                      example: https://example.com/webhook
                    events:
                      type: array
                      items:
                        type: string
                      example:
                        - invoice.paid
                        - invoice.created
                    isActive:
                      type: boolean
                      example: true
                    createdAt:
                      type: string
                      format: date-time
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
    post:
      summary: Create a new webhook
      description: Creates a new webhook endpoint to receive events from the platform
      tags:
        - Integrations
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - url
                - events
              properties:
                name:
                  type: string
                  example: Invoice Paid Webhook
                description:
                  type: string
                  example: Receive notifications when invoices are paid
                url:
                  type: string
                  format: uri
                  example: https://example.com/webhook/invoice-paid
                events:
                  type: array
                  items:
                    type: string
                  example:
                    - invoice.paid
                    - invoice.created
                secret:
                  type: string
                  description: >-
                    Webhook secret for signature verification (auto-generated if
                    not provided)
                retryPolicy:
                  type: object
                  properties:
                    maxRetries:
                      type: integer
                      default: 3
                    retryDelay:
                      type: integer
                      default: 1000
                headers:
                  type: object
                  description: Custom headers to include in webhook requests
                filters:
                  type: object
                  description: Event filters
                timeout:
                  type: integer
                  default: 30000
                  description: Request timeout in milliseconds
                organizationId:
                  type: string
      responses:
        '201':
          description: Webhook created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    example: webhook_123
                  name:
                    type: string
                  url:
                    type: string
                  secret:
                    type: string
                    description: Generated webhook secret for signature verification
        '400':
          description: Bad request - Invalid input data
        '401':
          description: Unauthorized - Authentication required
        '500':
          description: Internal server error
  /api/webhooks/sentry:
    get:
      summary: Get Sentry
      description: /webhooks/sentry endpoint.
      tags:
        - Webhooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Sentry
      description: /webhooks/sentry endpoint.
      tags:
        - Webhooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/webhooks/shopify:
    post:
      summary: Create or submit Shopify
      description: /webhooks/shopify endpoint.
      tags:
        - Webhooks
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /webhooks/stripe:
    post:
      summary: Stripe webhook handler
      description: >-
        Handles Stripe webhook events for subscriptions and billing
        (subscription created/updated/deleted, invoice payment succeeded/failed,
        etc.). Verifies Stripe signature. Emits workflow events for n8n.
      tags:
        - webhooks
        - billing
      parameters:
        - in: header
          name: stripe-signature
          required: true
          schema:
            type: string
          description: Stripe webhook signature for verification
      requestBody:
        content:
          application/json:
            schema:
              type: object
              description: Raw Stripe event payload
      responses:
        '200':
          description: Processed
        '400':
          description: Invalid payload or signature
        '500':
          description: Internal server error
  /workflows/{id}/duplicate:
    post:
      summary: Duplicate workflow
      description: >-
        Creates a copy of an existing workflow with name suffixed by (Copy).
        Requires authentication.
      tags:
        - workflows
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Workflow ID
      responses:
        '201':
          description: Duplicated workflow
        '400':
          description: Invalid workflow ID
        '401':
          description: Unauthorized
        '404':
          description: Workflow not found
        '500':
          description: Internal server error
  /workflows/{id}/execute:
    post:
      summary: Execute workflow
      description: >-
        Manually executes an active workflow. Body may include triggerData.
        Requires authentication.
      tags:
        - workflows
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Workflow ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                triggerData:
                  type: object
      responses:
        '200':
          description: Execution result
        '400':
          description: Invalid workflow ID or workflow must be active
        '401':
          description: Unauthorized
        '404':
          description: Workflow not found
        '500':
          description: Internal server error
  /workflows/{id}/executions:
    get:
      summary: List workflow executions
      description: >-
        Returns executions for the given workflow with optional filters (status,
        limit, offset). Requires authentication.
      tags:
        - workflows
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Workflow ID
        - in: query
          name: status
          schema:
            type: string
            enum:
              - pending
              - running
              - completed
              - failed
              - cancelled
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: List of executions
        '400':
          description: Invalid workflow ID
        '401':
          description: Unauthorized
        '404':
          description: Workflow not found
        '500':
          description: Internal server error
  /workflows/{id}/logs:
    get:
      summary: Get workflow logs
      description: >-
        Returns execution logs for the given workflow. Query params executionId,
        level, limit (default 100), offset (default 0). Requires authentication.
      tags:
        - workflows
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Workflow ID
        - in: query
          name: executionId
          schema:
            type: string
        - in: query
          name: level
          schema:
            type: string
        - in: query
          name: limit
          schema:
            type: integer
            default: 100
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: List of workflow logs
        '400':
          description: Invalid workflow ID
        '401':
          description: Unauthorized
        '404':
          description: Workflow not found
        '500':
          description: Internal server error
  /workflows/{id}:
    get:
      summary: Get workflow by ID
      description: Returns a single workflow by ID for the authenticated user.
      tags:
        - workflows
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Workflow ID
      responses:
        '200':
          description: Workflow object
        '400':
          description: Invalid workflow ID
        '401':
          description: Unauthorized
        '404':
          description: Workflow not found
        '500':
          description: Internal server error
    put:
      summary: Update workflow
      description: Updates an existing workflow.
      tags:
        - workflows
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                description:
                  type: string
                triggerConfig:
                  type: object
                actions:
                  type: array
                status:
                  type: string
      responses:
        '200':
          description: Updated workflow
        '400':
          description: Invalid JSON or workflow ID
        '401':
          description: Unauthorized
        '404':
          description: Workflow not found
        '500':
          description: Internal server error
    delete:
      summary: Delete workflow
      description: Deletes a workflow for the authenticated user.
      tags:
        - workflows
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
        '400':
          description: Invalid workflow ID
        '401':
          description: Unauthorized
        '404':
          description: Workflow not found
        '500':
          description: Internal server error
  /api/workflows/{id}/test:
    post:
      summary: Test workflow (dry run)
      description: Executes a workflow in test mode without persisting results.
      tags:
        - Workflows
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Workflow ID
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                triggerData:
                  type: object
                  description: Optional trigger payload for the test run
      responses:
        '200':
          description: Test run result (success, output, duration, error)
        '401':
          description: Unauthorized
        '404':
          description: Workflow not found
  /workflows/actions:
    get:
      summary: Get available workflow actions
      description: >-
        Returns the list of available workflow actions that can be used when
        creating or updating workflows.
      tags:
        - workflows
      responses:
        '200':
          description: Array of available actions
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/workflows/executions/{id}/rerun:
    post:
      summary: Rerun workflow execution
      description: >-
        Creates a new execution with the same trigger data as the given
        execution.
      tags:
        - Workflows
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Execution ID to rerun
      responses:
        '200':
          description: Rerun initiated; returns newExecutionId and status
        '401':
          description: Unauthorized
        '404':
          description: Execution or workflow not found
  /workflows:
    get:
      summary: List workflows
      description: >-
        Returns workflows for the authenticated user with optional filters
        (status, search, limit, offset).
      tags:
        - workflows
      parameters:
        - in: query
          name: status
          schema:
            type: string
            enum:
              - active
              - inactive
              - draft
              - archived
        - in: query
          name: search
          schema:
            type: string
        - in: query
          name: limit
          schema:
            type: integer
        - in: query
          name: offset
          schema:
            type: integer
      responses:
        '200':
          description: Workflows list
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create workflow
      description: >-
        Creates a new workflow. Requires name, triggerConfig, and at least one
        action.
      tags:
        - workflows
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - triggerConfig
                - actions
              properties:
                name:
                  type: string
                description:
                  type: string
                organizationId:
                  type: string
                triggerConfig:
                  type: object
                actions:
                  type: array
                conditions:
                  type: array
                status:
                  type: string
                  enum:
                    - draft
                    - active
      responses:
        '201':
          description: Created workflow
        '400':
          description: Invalid JSON or missing required fields
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/workflows/templates/{id}/instantiate:
    post:
      summary: Create workflow from template
      description: >-
        Instantiates a new workflow from a template with optional name,
        description, and organization.
      tags:
        - Workflows
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: string
          description: Template ID
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
              properties:
                name:
                  type: string
                description:
                  type: string
                organizationId:
                  type: string
      responses:
        '201':
          description: Workflow created from template
        '400':
          description: Name is required
        '401':
          description: Unauthorized
        '404':
          description: Template not found
  /workflows/templates/import:
    post:
      summary: Import workflow template
      description: >-
        Imports a workflow template from JSON body. Body requires name and
        templateConfig (steps, triggers, variables, settings). Requires
        authentication.
      tags:
        - workflows
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - templateConfig
              properties:
                name:
                  type: string
                description:
                  type: string
                category:
                  type: string
                templateConfig:
                  type: object
                tags:
                  type: array
                  items:
                    type: string
      responses:
        '201':
          description: Imported template
        '400':
          description: Validation error
        '401':
          description: Unauthorized
        '404':
          description: User not found
        '500':
          description: Internal server error
  /workflows/templates:
    get:
      summary: List workflow templates
      description: >-
        Returns public workflow templates with optional filters (category,
        isOfficial, limit, offset). Requires authentication.
      tags:
        - workflows
      parameters:
        - in: query
          name: category
          schema:
            type: string
        - in: query
          name: isOfficial
          schema:
            type: boolean
        - in: query
          name: limit
          schema:
            type: integer
            default: 50
        - in: query
          name: offset
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: List of templates
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
    post:
      summary: Create workflow template
      description: >-
        Creates a new workflow template. Body requires name and templateConfig
        (steps, triggers, variables, settings). Requires authentication.
      tags:
        - workflows
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - name
                - templateConfig
              properties:
                name:
                  type: string
                description:
                  type: string
                category:
                  type: string
                templateConfig:
                  type: object
                tags:
                  type: array
                  items:
                    type: string
      responses:
        '201':
          description: Created template
        '400':
          description: Invalid JSON or validation error
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /workflows/triggers:
    get:
      summary: Get available workflow triggers
      description: >-
        Returns the list of available workflow triggers that can be used when
        creating or updating workflows. Requires authentication.
      tags:
        - workflows
      responses:
        '200':
          description: Array of available triggers
        '401':
          description: Unauthorized
        '500':
          description: Internal server error
  /api/workspaces/{workspaceId}/clients/{clientId}:
    get:
      summary: Get resource
      description: /workspaces/{workspaceId}/clients/{clientId} endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /workspaces/{workspaceId}/clients/{clientId} endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /workspaces/{workspaceId}/clients/{clientId} endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/workspaces/{workspaceId}/clients:
    get:
      summary: Get Clients
      description: /workspaces/{workspaceId}/clients endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Clients
      description: /workspaces/{workspaceId}/clients endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/workspaces/{workspaceId}/members/{memberId}:
    patch:
      summary: Update resource
      description: /workspaces/{workspaceId}/members/{memberId} endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /workspaces/{workspaceId}/members/{memberId} endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/workspaces/{workspaceId}/members:
    get:
      summary: Get Members
      description: /workspaces/{workspaceId}/members endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    post:
      summary: Create or submit Members
      description: /workspaces/{workspaceId}/members endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
  /api/workspaces/{workspaceId}/metrics:
    get:
      summary: Get Metrics
      description: /workspaces/{workspaceId}/metrics endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/workspaces/{workspaceId}:
    get:
      summary: Get resource
      description: /workspaces/{workspaceId} endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    patch:
      summary: Update resource
      description: /workspaces/{workspaceId} endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
    delete:
      summary: Delete resource
      description: /workspaces/{workspaceId} endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '404':
          description: Not found
        '500':
          description: Server error
  /api/workspaces:
    get:
      summary: Get Workspaces
      description: /workspaces endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
    post:
      summary: Create or submit Workspaces
      description: /workspaces endpoint.
      tags:
        - Workspaces
      responses:
        '200':
          description: OK
        '400':
          description: Bad request
        '401':
          description: Unauthorized
        '500':
          description: Server error
