{
  "openapi": "3.0.3",
  "info": {
    "title": "SeggWat Service API",
    "version": "1.3.0",
    "description": "API for health checks, submitting feedback, managing feedback data, ratings, ideas, churn events, and contact messages. Includes project-level summary and stats endpoints optimised for mobile dashboards."
  },
  "servers": [
    {
      "url": "https://seggwat.com/api/v1",
      "description": "Production server"
    },
    {
      "url": "https://seggwat.oxidt.com/api/v1",
      "description": "Staging server"
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "operationId": "getDeepHealth",
        "summary": "Deep health check",
        "description": "Returns overall status.",
        "responses": {
          "200": {
            "description": "Detailed health information including subsystem statuses.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HealthStatus"
                },
                "examples": {
                  "allHealthy": {
                    "summary": "All systems healthy",
                    "value": {
                      "status": "ok"
                    }
                  },
                  "degraded": {
                    "summary": "Degraded service",
                    "value": {
                      "status": "degraded"
                    }
                  }
                }
              }
            }
          }
        },
        "tags": [
          "Health"
        ]
      }
    },
    "/feedback/submit": {
      "post": {
        "operationId": "submitFeedback",
        "summary": "Submit feedback",
        "description": "Submit a feedback message for a specific project. Feedback is stored and can be retrieved for analysis and customer support purposes.",
        "parameters": [
          {
            "$ref": "#/components/parameters/RefererHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Feedback submission payload containing project identifier and message.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FeedbackSubmission"
              },
              "examples": {
                "basicFeedback": {
                  "summary": "Simple feedback submission",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "message": "Great feature! Would love to see dark mode support."
                  }
                },
                "feedbackWithPath": {
                  "summary": "Feedback with URL path",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "message": "The checkout button is not working properly.",
                    "path": "/checkout"
                  }
                },
                "feedbackWithVersion": {
                  "summary": "Feedback with version tracking",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "message": "Dashboard loading is slower after the update.",
                    "path": "/dashboard",
                    "version": "1.2.3"
                  }
                },
                "feedbackWithUser": {
                  "summary": "Feedback with user tracking",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "message": "The export feature is not working for large datasets.",
                    "path": "/reports/export",
                    "version": "2.1.0",
                    "submitted_by": "user_12345"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Feedback successfully accepted and processed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SubmissionResult"
                },
                "examples": {
                  "stored": {
                    "summary": "Feedback stored successfully",
                    "value": {
                      "status": "stored"
                    }
                  },
                  "queued": {
                    "summary": "Feedback queued for processing",
                    "value": {
                      "status": "queued"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation error in the request payload.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "missingProjectKey": {
                    "summary": "Missing project key",
                    "value": {
                      "error": "validation_error",
                      "message": "project_key is required"
                    }
                  },
                  "invalidUUID": {
                    "summary": "Invalid UUID format",
                    "value": {
                      "error": "validation_error",
                      "message": "project_key must be a valid UUID"
                    }
                  },
                  "emptyMessage": {
                    "summary": "Empty message",
                    "value": {
                      "error": "validation_error",
                      "message": "message cannot be empty"
                    }
                  }
                }
              }
            }
          }
        },
        "tags": [
          "Feedback"
        ]
      }
    },
    "/projects": {
      "get": {
        "operationId": "listProjects",
        "summary": "List all projects",
        "description": "Retrieve all projects belonging to the authenticated organization.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "List of projects with their metadata and feedback counts.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectListResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Projects"
        ]
      },
      "post": {
        "operationId": "createProject",
        "summary": "Create a project",
        "description": "Create a project, or return the existing one with the same name (trimmed, case-insensitive) in the organization, so setup can be re-run safely. Runs the same trial, plan-limit and input checks as the dashboard. Requires full access or the `project:write` scope; a project-restricted key is refused.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateProjectRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Project created.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateProjectResponse"
                }
              }
            }
          },
          "200": {
            "description": "A project with this name already existed and was returned unchanged (`created: false`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateProjectResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid name, description or origin.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Missing scope, project-restricted key, no org access, no active trial, or the plan's project limit is reached. The message carries a billing link when billing is the cause.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Projects"
        ]
      }
    },
    "/projects/{project_id}": {
      "get": {
        "operationId": "getProject",
        "summary": "Get single project",
        "description": "Retrieve a single project by its ID. Useful for deep-linking into a specific project from a mobile app or integration without fetching the full project list.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "responses": {
          "200": {
            "description": "The requested project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Project"
                },
                "examples": {
                  "example": {
                    "summary": "A project",
                    "value": {
                      "id": "507f1f77bcf86cd799439011",
                      "key": "550e8400-e29b-41d4-a716-446655440000",
                      "name": "My Web App",
                      "description": "Main production application",
                      "allowed_origins": [
                        "https://example.com"
                      ],
                      "org_id": "507f1f77bcf86cd799439022",
                      "feedback_count": 142
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Projects"
        ]
      }
    },
    "/projects/{project_id}/summary": {
      "get": {
        "operationId": "getProjectSummary",
        "summary": "Get project summary",
        "description": "All-in-one project overview that returns the project details plus feedback counts (broken down by type and status), churn stats, idea counts, contact message counts, rating statistics (helpful, star, NPS), and a list of recent feedback items in a single request. Designed to minimise round trips for mobile dashboard home screens.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "responses": {
          "200": {
            "description": "Project summary with aggregated statistics.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ProjectSummary"
                },
                "examples": {
                  "example": {
                    "summary": "Project summary",
                    "value": {
                      "project": {
                        "id": "507f1f77bcf86cd799439011",
                        "key": "550e8400-e29b-41d4-a716-446655440000",
                        "name": "My Web App",
                        "description": "Main production application",
                        "allowed_origins": [
                          "https://example.com"
                        ],
                        "org_id": "507f1f77bcf86cd799439022",
                        "feedback_count": 142
                      },
                      "feedback": {
                        "total": 142,
                        "current_month": 18,
                        "last_month": 24,
                        "by_type": {
                          "bug": 32,
                          "feature": 55,
                          "praise": 21,
                          "question": 14,
                          "improvement": 12,
                          "other": 8
                        },
                        "by_status": {
                          "new": 41,
                          "active": 28,
                          "hold": 7,
                          "closed": 33,
                          "resolved": 18
                        }
                      },
                      "churn": {
                        "total": 12,
                        "this_month": 3,
                        "last_month": 5,
                        "by_reason": {
                          "TooExpensive": 4,
                          "MissingFeatures": 3,
                          "SwitchedService": 2,
                          "Unused": 2,
                          "Other": 1,
                          "LowQuality": 0,
                          "TooComplex": 0,
                          "CustomerService": 0,
                          "Unknown": 0
                        }
                      },
                      "ideas": {
                        "total": 37,
                        "pending": 5
                      },
                      "messages": {
                        "total": 9
                      },
                      "ratings": {
                        "helpful": {
                          "total": 250,
                          "helpful": 215,
                          "not_helpful": 35,
                          "percentage": 86.0
                        },
                        "star": {
                          "total": 85,
                          "average": 4.2,
                          "distribution": {
                            "1": 2,
                            "2": 5,
                            "3": 15,
                            "4": 30,
                            "5": 33
                          }
                        },
                        "nps": {
                          "total": 0,
                          "score": 0,
                          "promoters": 0,
                          "passives": 0,
                          "detractors": 0,
                          "distribution": {}
                        }
                      },
                      "recent_feedback": [
                        {
                          "id": "507f1f77bcf86cd799439031",
                          "message_preview": "The export button doesn't work in Firefox when I try to download...",
                          "feedback_type": "Bug",
                          "path": "/dashboard/reports",
                          "created_at": "2024-01-15T14:32:00Z"
                        },
                        {
                          "id": "507f1f77bcf86cd799439032",
                          "message_preview": "Would love a dark mode option for the main interface",
                          "feedback_type": "Feature",
                          "path": "/settings",
                          "created_at": "2024-01-15T11:20:00Z"
                        },
                        {
                          "id": "507f1f77bcf86cd799439033",
                          "message_preview": "Great update! The new search is much faster than before",
                          "feedback_type": "Praise",
                          "path": null,
                          "created_at": "2024-01-14T09:05:00Z"
                        }
                      ]
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Projects"
        ]
      }
    },
    "/projects/{project_id}/feedback": {
      "get": {
        "operationId": "listProjectFeedback",
        "summary": "List project feedback",
        "description": "Retrieve a paginated list of feedback items for a specific project with optional filtering.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "page",
            "in": "query",
            "description": "Page number (1-indexed)",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of items per page",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter by feedback status",
            "schema": {
              "$ref": "#/components/schemas/FeedbackStatus"
            }
          },
          {
            "name": "type",
            "in": "query",
            "description": "Filter by feedback type",
            "schema": {
              "$ref": "#/components/schemas/FeedbackType"
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Search term to filter feedback by message content",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated list of feedback items.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FeedbackListResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Feedback"
        ]
      },
      "post": {
        "operationId": "createProjectFeedback",
        "summary": "Create feedback via API",
        "description": "Create a new feedback item for a project using API key authentication. Unlike the widget submit endpoint, this requires authentication and enforces subscription tier limits.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Feedback creation payload",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FeedbackCreateRequest"
              },
              "examples": {
                "basicFeedback": {
                  "summary": "Simple feedback creation",
                  "value": {
                    "message": "Customer reported a bug via support ticket"
                  }
                },
                "fullFeedback": {
                  "summary": "Feedback with all optional fields",
                  "value": {
                    "message": "User requested dark mode feature",
                    "type": "Feature",
                    "path": "/settings",
                    "version": "2.1.0",
                    "submitted_by": "user-123"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Feedback created successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feedback"
                }
              }
            }
          },
          "400": {
            "description": "Bad request - validation error or trial limit reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "emptyMessage": {
                    "summary": "Empty message",
                    "value": {
                      "error": "bad_request",
                      "message": "Message cannot be empty"
                    }
                  },
                  "trialLimitReached": {
                    "summary": "Trial tier limit reached",
                    "value": {
                      "error": "bad_request",
                      "message": "Trial tier feedback limit reached (50 items). Please upgrade your plan."
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Feedback"
        ]
      }
    },
    "/projects/{project_id}/feedback/stats": {
      "get": {
        "operationId": "getProjectFeedbackStats",
        "summary": "Get feedback statistics",
        "description": "Retrieve feedback counts for a project — total, current calendar month, and previous calendar month. Useful for home screen badges and trend indicators in mobile apps.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "responses": {
          "200": {
            "description": "Feedback counts for the project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FeedbackCounts"
                },
                "examples": {
                  "example": {
                    "summary": "Feedback stats",
                    "value": {
                      "total": 142,
                      "current_month": 18,
                      "last_month": 24
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Feedback"
        ]
      }
    },
    "/projects/{project_id}/feedback/{feedback_id}": {
      "get": {
        "operationId": "getProjectFeedback",
        "summary": "Get single feedback",
        "description": "Retrieve a single feedback item by ID.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "feedback_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the feedback item",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The requested feedback item.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feedback"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or feedback not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Feedback"
        ]
      },
      "patch": {
        "operationId": "updateProjectFeedback",
        "summary": "Update feedback",
        "description": "Update the message, type, or status of a feedback item. At least one field must be provided.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "feedback_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the feedback item",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Fields to update. At least one field must be provided.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FeedbackUpdate"
              },
              "examples": {
                "updateStatus": {
                  "summary": "Update status only",
                  "value": {
                    "status": "Active"
                  }
                },
                "updateType": {
                  "summary": "Update type only",
                  "value": {
                    "type": "Bug"
                  }
                },
                "updateMultiple": {
                  "summary": "Update multiple fields",
                  "value": {
                    "status": "Resolved",
                    "type": "Feature",
                    "message": "Updated feedback message"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated feedback item.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Feedback"
                }
              }
            }
          },
          "400": {
            "description": "Validation error - no fields provided or invalid values.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or feedback not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Feedback"
        ]
      },
      "delete": {
        "operationId": "deleteProjectFeedback",
        "summary": "Delete feedback",
        "description": "Soft-delete a feedback item (sets archived=true). The item will no longer appear in list queries.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "feedback_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the feedback item",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Feedback successfully deleted (no content returned)."
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or feedback not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Feedback"
        ]
      }
    },
    "/projects/{project_id}/ratings": {
      "get": {
        "operationId": "listProjectRatings",
        "summary": "List project ratings",
        "description": "Retrieve a paginated list of ratings for a specific project with optional filtering by type and path.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "page",
            "in": "query",
            "description": "Page number (1-indexed)",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of items per page",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "type",
            "in": "query",
            "description": "Filter by rating type",
            "schema": {
              "$ref": "#/components/schemas/RatingType"
            }
          },
          {
            "name": "value",
            "in": "query",
            "description": "Legacy filter: Filter by helpful rating value (true = helpful, false = not helpful). Only applies to helpful type ratings.",
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "path",
            "in": "query",
            "description": "Filter by page path where the rating was submitted",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated list of rating items.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RatingListResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ratings"
        ]
      },
      "post": {
        "operationId": "createProjectRating",
        "summary": "Create rating via API (helpful type)",
        "description": "Create a new helpful rating (thumbs up/down) for a project using API key authentication. For other rating types (star, NPS), use the /ratings/typed endpoint.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Rating creation payload",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RatingCreateRequest"
              },
              "examples": {
                "helpful": {
                  "summary": "Helpful rating",
                  "value": {
                    "value": true,
                    "path": "/docs/getting-started"
                  }
                },
                "notHelpful": {
                  "summary": "Not helpful rating with tracking",
                  "value": {
                    "value": false,
                    "path": "/docs/advanced",
                    "version": "2.1.0",
                    "submitted_by": "user-abc-123"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rating created successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Rating"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ratings"
        ]
      }
    },
    "/projects/{project_id}/ratings/typed": {
      "post": {
        "operationId": "createProjectRatingTyped",
        "summary": "Create typed rating via API",
        "description": "Create a new rating of any type (helpful, star, NPS) for a project using API key authentication.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Typed rating creation payload",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TypedRatingCreateRequest"
              },
              "examples": {
                "helpful": {
                  "summary": "Helpful rating",
                  "value": {
                    "rating": {
                      "type": "helpful",
                      "value": true
                    },
                    "context": {
                      "path": "/docs/getting-started"
                    }
                  }
                },
                "star": {
                  "summary": "Star rating",
                  "value": {
                    "rating": {
                      "type": "star",
                      "value": 4,
                      "max_stars": 5
                    },
                    "context": {
                      "path": "/products/widget",
                      "version": "2.0.0"
                    }
                  }
                },
                "nps": {
                  "summary": "NPS rating",
                  "value": {
                    "rating": {
                      "type": "nps",
                      "value": 9
                    },
                    "context": {
                      "submitted_by": "user-123"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rating created successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Rating"
                }
              }
            }
          },
          "400": {
            "description": "Invalid rating value for the specified type.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ratings"
        ]
      }
    },
    "/projects/{project_id}/ratings/stats": {
      "get": {
        "operationId": "getProjectRatingStats",
        "summary": "Get helpful rating statistics (legacy)",
        "description": "Retrieve aggregated helpful rating statistics for a project. For other rating types, use /ratings/stats/typed.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "path",
            "in": "query",
            "description": "Filter statistics by page path",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Aggregated helpful rating statistics.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HelpfulStats"
                },
                "examples": {
                  "projectStats": {
                    "summary": "Project-wide statistics",
                    "value": {
                      "total": 250,
                      "helpful": 215,
                      "not_helpful": 35,
                      "percentage": 86.0
                    }
                  },
                  "pageStats": {
                    "summary": "Statistics for specific page",
                    "value": {
                      "total": 42,
                      "helpful": 38,
                      "not_helpful": 4,
                      "percentage": 90.48
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ratings"
        ]
      }
    },
    "/projects/{project_id}/ratings/stats/typed": {
      "get": {
        "operationId": "getTypedRatingStats",
        "summary": "Get typed rating statistics",
        "description": "Retrieve aggregated statistics for any rating type (helpful, star, NPS).",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "type",
            "in": "query",
            "description": "Rating type to get statistics for (defaults to helpful)",
            "schema": {
              "$ref": "#/components/schemas/RatingType"
            }
          },
          {
            "name": "path",
            "in": "query",
            "description": "Filter statistics by page path",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Aggregated rating statistics. Response structure varies by rating type.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RatingStats"
                },
                "examples": {
                  "helpfulStats": {
                    "summary": "Helpful rating statistics",
                    "value": {
                      "type": "helpful",
                      "total": 250,
                      "helpful": 215,
                      "not_helpful": 35,
                      "percentage": 86.0
                    }
                  },
                  "starStats": {
                    "summary": "Star rating statistics",
                    "value": {
                      "type": "star",
                      "total": 85,
                      "average": 4.2,
                      "distribution": {
                        "1": 2,
                        "2": 5,
                        "3": 15,
                        "4": 30,
                        "5": 33
                      }
                    }
                  },
                  "npsStats": {
                    "summary": "NPS rating statistics",
                    "value": {
                      "type": "nps",
                      "total": 200,
                      "score": 45,
                      "promoters": 120,
                      "passives": 50,
                      "detractors": 30,
                      "distribution": {
                        "0": 5,
                        "1": 3,
                        "2": 2,
                        "3": 5,
                        "4": 5,
                        "5": 5,
                        "6": 5,
                        "7": 25,
                        "8": 25,
                        "9": 50,
                        "10": 70
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ratings"
        ]
      }
    },
    "/projects/{project_id}/ratings/stats/grouped": {
      "get": {
        "operationId": "getGroupedRatingStats",
        "summary": "Get grouped rating statistics",
        "description": "Retrieve aggregated statistics grouped by path, version, or day.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "type",
            "in": "query",
            "description": "Rating type to get statistics for (defaults to helpful)",
            "schema": {
              "$ref": "#/components/schemas/RatingType"
            }
          },
          {
            "name": "group_by",
            "in": "query",
            "description": "Field to group statistics by",
            "schema": {
              "$ref": "#/components/schemas/StatsGroupBy"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Grouped rating statistics.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GroupedStats"
                },
                "examples": {
                  "byPath": {
                    "summary": "Statistics grouped by path",
                    "value": {
                      "groups": {
                        "/docs/intro": {
                          "type": "helpful",
                          "total": 50,
                          "helpful": 45,
                          "not_helpful": 5,
                          "percentage": 90.0
                        },
                        "/docs/advanced": {
                          "type": "helpful",
                          "total": 30,
                          "helpful": 20,
                          "not_helpful": 10,
                          "percentage": 66.7
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ratings"
        ]
      }
    },
    "/projects/{project_id}/ratings/{rating_id}": {
      "get": {
        "operationId": "getProjectRating",
        "summary": "Get single rating",
        "description": "Retrieve a single rating item by ID.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "rating_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the rating item",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The requested rating item.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Rating"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or rating not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ratings"
        ]
      },
      "delete": {
        "operationId": "deleteProjectRating",
        "summary": "Delete rating",
        "description": "Soft-delete a rating item (sets archived=true). The item will no longer appear in list queries or statistics.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "rating_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the rating item",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Rating successfully deleted (no content returned)."
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or rating not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ratings"
        ]
      }
    },
    "/projects/{project_id}/ideas": {
      "get": {
        "operationId": "listIdeas",
        "summary": "List ideas",
        "description": "Retrieve a paginated list of ideas for a specific project with optional filtering. All statuses are returned (including Pending, Rejected) — unlike the public widget endpoint which only shows publicly visible statuses.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "page",
            "in": "query",
            "description": "Page number (1-indexed)",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of items per page",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter by idea status",
            "schema": {
              "$ref": "#/components/schemas/IdeaStatus"
            }
          },
          {
            "name": "tag_id",
            "in": "query",
            "description": "Filter by tag identifier",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Search term to filter ideas by title or description",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "sort_by_votes",
            "in": "query",
            "description": "Sort results by vote count descending",
            "schema": {
              "type": "boolean",
              "default": false
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated list of ideas.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IdeaListResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ideas"
        ]
      },
      "post": {
        "operationId": "createIdea",
        "summary": "Create idea",
        "description": "Create a new idea for a project using API key authentication.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Idea creation payload",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IdeaCreateRequest"
              },
              "examples": {
                "basic": {
                  "summary": "Simple idea",
                  "value": {
                    "title": "Add dark mode support"
                  }
                },
                "full": {
                  "summary": "Feature idea with all optional fields",
                  "value": {
                    "title": "Add dark mode support",
                    "description": "Users have requested a dark theme for nighttime use",
                    "tag_ids": [
                      "507f1f77bcf86cd799439050"
                    ],
                    "author_email": "customer@example.com"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Idea created successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Idea"
                }
              }
            }
          },
          "400": {
            "description": "Validation error - title is required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ideas"
        ]
      }
    },
    "/projects/{project_id}/ideas/{idea_id}": {
      "get": {
        "operationId": "getIdea",
        "summary": "Get idea",
        "description": "Retrieve a single idea by ID.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "idea_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the idea",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The requested idea.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Idea"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or idea not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ideas"
        ]
      },
      "patch": {
        "operationId": "updateIdea",
        "summary": "Update idea",
        "description": "Update the title, description, status, tags, or admin response of an idea. At least one field must be provided.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "idea_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the idea",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Fields to update. At least one field must be provided.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IdeaUpdate"
              },
              "examples": {
                "updateStatus": {
                  "summary": "Update status only",
                  "value": {
                    "status": "Planned"
                  }
                },
                "updateWithResponse": {
                  "summary": "Update status and add admin response",
                  "value": {
                    "status": "Planned",
                    "admin_response": "Great idea! We have this on our roadmap for Q2."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated idea.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Idea"
                }
              }
            }
          },
          "400": {
            "description": "Validation error - no fields provided or invalid values.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or idea not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ideas"
        ]
      },
      "delete": {
        "operationId": "deleteIdea",
        "summary": "Delete idea",
        "description": "Soft-delete an idea (sets archived=true). The item will no longer appear in list queries.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "idea_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the idea",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Idea successfully deleted (no content returned)."
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or idea not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ideas"
        ]
      }
    },
    "/projects/{project_id}/ideas/{idea_id}/merge": {
      "post": {
        "operationId": "mergeIdea",
        "summary": "Merge idea",
        "description": "Merge a duplicate idea (the path's `idea_id`) into a canonical idea in the same project. Votes move to the target (a voter who backed both counts once), comments move with them, and the source becomes `Duplicate` with `merged_into_id` set to the target. Requires the `idea:write` scope.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "idea_id",
            "in": "path",
            "required": true,
            "description": "The duplicate idea to merge away",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/IdeaMergeRequest"
              },
              "examples": {
                "merge": {
                  "summary": "Merge into the canonical idea",
                  "value": {
                    "target_id": "507f1f77bcf86cd799439011"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The merge result.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IdeaMergeResult"
                }
              }
            }
          },
          "400": {
            "description": "Validation error - self-merge, source already a duplicate, target merged away, or target in another project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key lacks the idea:write scope or access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project, source idea, or target idea not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ideas"
        ]
      }
    },
    "/projects/{project_id}/ideas/{idea_id}/comments": {
      "get": {
        "operationId": "listIdeaComments",
        "summary": "List idea comments",
        "description": "Retrieve threaded comments for a specific idea. Returns full, unmasked comment data (user IDs and emails included) since API-key consumers are product owners. Replies are nested inside each top-level comment thread.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "idea_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the idea",
            "schema": {
              "type": "string"
            },
            "example": "507f1f77bcf86cd799439055"
          },
          {
            "name": "offset",
            "in": "query",
            "description": "Number of top-level comment threads to skip",
            "schema": {
              "type": "integer",
              "default": 0,
              "minimum": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of top-level comment threads to return",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Threaded comments for the idea.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/IdeaCommentListResponse"
                },
                "examples": {
                  "example": {
                    "summary": "Two top-level comments, one with a reply",
                    "value": {
                      "comments": [
                        {
                          "comment": {
                            "id": "507f1f77bcf86cd799439061",
                            "idea_id": "507f1f77bcf86cd799439055",
                            "parent_id": null,
                            "body": "Great idea! Would love this feature.",
                            "user_id": null,
                            "user_email": null,
                            "enduser_id": "enduser-42",
                            "enduser_email": "alice@example.com",
                            "created_at": "2024-01-15T10:30:00Z",
                            "archived": false
                          },
                          "replies": [
                            {
                              "id": "507f1f77bcf86cd799439062",
                              "idea_id": "507f1f77bcf86cd799439055",
                              "parent_id": "507f1f77bcf86cd799439061",
                              "body": "Thanks! We're planning this for Q2.",
                              "user_id": "usr-team-member",
                              "user_email": "team@example.com",
                              "enduser_id": null,
                              "enduser_email": null,
                              "created_at": "2024-01-15T11:00:00Z",
                              "archived": false
                            }
                          ]
                        },
                        {
                          "comment": {
                            "id": "507f1f77bcf86cd799439063",
                            "idea_id": "507f1f77bcf86cd799439055",
                            "parent_id": null,
                            "body": "Can you add priority sorting too?",
                            "user_id": null,
                            "user_email": null,
                            "enduser_id": "enduser-99",
                            "enduser_email": null,
                            "created_at": "2024-01-16T09:00:00Z",
                            "archived": false
                          },
                          "replies": []
                        }
                      ],
                      "has_more": false,
                      "total": 2
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or idea not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Ideas"
        ]
      }
    },
    "/projects/{project_id}/messages": {
      "get": {
        "operationId": "listMessages",
        "summary": "List messages",
        "description": "Retrieve a paginated list of contact messages for a specific project with optional filtering.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "page",
            "in": "query",
            "description": "Page number (1-indexed)",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Number of items per page",
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "status",
            "in": "query",
            "description": "Filter by contact message status",
            "schema": {
              "$ref": "#/components/schemas/ContactMessageStatus"
            }
          },
          {
            "name": "search",
            "in": "query",
            "description": "Search term to filter messages by name, email, subject, or message content",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Paginated list of contact messages.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactMessageListResponse"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Messages"
        ]
      }
    },
    "/projects/{project_id}/messages/{message_id}": {
      "get": {
        "operationId": "getMessage",
        "summary": "Get message",
        "description": "Retrieve a single contact message by ID.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "message_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the contact message",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The requested contact message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactMessage"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or message not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Messages"
        ]
      },
      "patch": {
        "operationId": "updateMessageStatus",
        "summary": "Update message status",
        "description": "Update the status of a contact message. The status field is required.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "message_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the contact message",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Status update payload. The status field is required.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ContactMessageStatusUpdate"
              },
              "examples": {
                "markRead": {
                  "summary": "Mark as read",
                  "value": {
                    "status": "Read"
                  }
                },
                "markReplied": {
                  "summary": "Mark as replied",
                  "value": {
                    "status": "Replied"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated contact message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ContactMessage"
                }
              }
            }
          },
          "400": {
            "description": "Validation error - status field is required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or message not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Messages"
        ]
      },
      "delete": {
        "operationId": "deleteMessage",
        "summary": "Delete message",
        "description": "Soft-delete a contact message (sets archived=true). The item will no longer appear in list queries.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "message_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the contact message",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "204": {
            "description": "Contact message successfully deleted (no content returned)."
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or message not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Messages"
        ]
      }
    },
    "/projects/{project_id}/churn": {
      "get": {
        "operationId": "listChurnEvents",
        "summary": "List churn events",
        "description": "Retrieve churn events (subscription cancellations) for a specific project, sorted by cancellation date descending. Churn events are created automatically when a customer cancels via a Polar or Stripe webhook integration.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of events to return (default: 100, max: 100)",
            "schema": {
              "type": "integer",
              "default": 100,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Array of churn events for the project.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ChurnEvent"
                  }
                },
                "examples": {
                  "example": {
                    "summary": "Two churn events",
                    "value": [
                      {
                        "id": "507f1f77bcf86cd799439011",
                        "project_id": "507f1f77bcf86cd799439022",
                        "provider": "Polar",
                        "subscription_id": "sub_abc123",
                        "customer_id": "cus_xyz",
                        "customer_email": "user@example.com",
                        "reason": "TooExpensive",
                        "comment": "Price is too high for my budget",
                        "product_name": "Starter Plan",
                        "canceled_at": "2024-01-15T10:30:00Z",
                        "created_at": "2024-01-15T10:30:05Z"
                      },
                      {
                        "id": "507f1f77bcf86cd799439033",
                        "project_id": "507f1f77bcf86cd799439022",
                        "provider": "Stripe",
                        "subscription_id": "sub_def456",
                        "customer_id": null,
                        "customer_email": null,
                        "reason": "MissingFeatures",
                        "comment": null,
                        "product_name": "Pro Plan",
                        "canceled_at": "2024-01-10T08:00:00Z",
                        "created_at": "2024-01-10T08:00:10Z"
                      }
                    ]
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Churn"
        ]
      }
    },
    "/projects/{project_id}/churn/stats": {
      "get": {
        "operationId": "getChurnStats",
        "summary": "Get churn statistics",
        "description": "Retrieve aggregated churn statistics for a specific project, including totals, monthly breakdowns, and counts grouped by cancellation reason.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "responses": {
          "200": {
            "description": "Aggregated churn statistics for the project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChurnStats"
                },
                "examples": {
                  "example": {
                    "summary": "Churn stats with reason breakdown",
                    "value": {
                      "total": 12,
                      "this_month": 3,
                      "last_month": 5,
                      "by_reason": {
                        "TooExpensive": 4,
                        "MissingFeatures": 3,
                        "SwitchedService": 2,
                        "Unused": 2,
                        "Other": 1,
                        "LowQuality": 0,
                        "TooComplex": 0,
                        "CustomerService": 0,
                        "Unknown": 0
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Churn"
        ]
      }
    },
    "/rating/submit": {
      "post": {
        "operationId": "submitRating",
        "summary": "Submit helpful rating (widget - legacy)",
        "description": "Submit a helpful rating (thumbs up/down) for a specific project. This endpoint is designed for widget integration and validates the origin against the project's allowed origins. For typed ratings, use /ratings.",
        "parameters": [
          {
            "$ref": "#/components/parameters/RefererHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Rating submission payload",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RatingSubmission"
              },
              "examples": {
                "helpful": {
                  "summary": "Helpful rating",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "value": true,
                    "path": "/docs/getting-started"
                  }
                },
                "notHelpful": {
                  "summary": "Not helpful rating with version",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "value": false,
                    "path": "/docs/advanced",
                    "version": "1.2.3"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Rating submitted successfully."
          },
          "403": {
            "description": "Origin not allowed for this project."
          },
          "404": {
            "description": "Project not found."
          }
        },
        "tags": [
          "Ratings"
        ]
      }
    },
    "/ratings": {
      "post": {
        "operationId": "submitUnifiedRating",
        "summary": "Submit typed rating (widget)",
        "description": "Submit a rating of any type (helpful, star, NPS) for a specific project. This is the unified endpoint supporting all rating types.",
        "parameters": [
          {
            "$ref": "#/components/parameters/RefererHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Unified rating submission payload",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/UnifiedRatingSubmission"
              },
              "examples": {
                "helpful": {
                  "summary": "Helpful rating",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "rating": {
                      "type": "helpful",
                      "value": true
                    },
                    "context": {
                      "path": "/docs/getting-started"
                    }
                  }
                },
                "star": {
                  "summary": "Star rating",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "rating": {
                      "type": "star",
                      "value": 5,
                      "max_stars": 5
                    },
                    "context": {
                      "path": "/products/widget"
                    }
                  }
                },
                "nps": {
                  "summary": "NPS rating",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "rating": {
                      "type": "nps",
                      "value": 9
                    },
                    "context": {
                      "path": "/checkout/complete"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Rating created successfully.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RatingCreatedResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid rating value for the specified type."
          },
          "403": {
            "description": "Origin not allowed for this project."
          },
          "404": {
            "description": "Project not found."
          }
        },
        "tags": [
          "Ratings"
        ]
      }
    },
    "/projects/{project_id}/ratings/stats/nps": {
      "get": {
        "operationId": "getNpsRatingStats",
        "summary": "Get NPS statistics",
        "description": "Aggregated NPS statistics for a project: NPS score (-100 to +100), promoter/passive/detractor counts, and the 0-10 distribution. Optionally filter by page path.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "path",
            "in": "query",
            "description": "Filter statistics by page path.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Aggregated NPS statistics.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NpsStats"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "NPS"
        ]
      }
    },
    "/surveys/events": {
      "post": {
        "operationId": "trackSurveyEvents",
        "summary": "Track survey widget events",
        "description": "Batched aggregate event tracking for the public Survey widget. The server stores only `(project, survey, day_utc, event_kind)` counters — no IP, user agent, fingerprint, or anonymous visitor ID is persisted. The widget therefore does not need to set tracking cookies or prompt the visitor for consent. Three event kinds are widget-fired (`shown`, `started`, `dismissed`); the others are incremented server-side: `dispatched` from the lifecycle dispatcher, `link_clicked` from the magic-link landing handler, and `submitted` from `POST /surveys/submit`.",
        "parameters": [
          {
            "$ref": "#/components/parameters/RefererHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Batch of widget events. Cap of 32 events per request — larger batches are rejected with 413.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SurveyEventsBatch"
              },
              "examples": {
                "shown": {
                  "summary": "Widget impression",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "events": [
                      {
                        "survey_id": "6630f1c7c2b3a40a1e9e1b22",
                        "kind": "shown"
                      }
                    ]
                  }
                },
                "started": {
                  "summary": "First answer recorded (engagement signal)",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "events": [
                      {
                        "survey_id": "6630f1c7c2b3a40a1e9e1b22",
                        "kind": "started"
                      }
                    ]
                  }
                },
                "dismissed": {
                  "summary": "Dismissal (close button or backdrop click)",
                  "value": {
                    "project_key": "550e8400-e29b-41d4-a716-446655440000",
                    "events": [
                      {
                        "survey_id": "6630f1c7c2b3a40a1e9e1b22",
                        "kind": "dismissed"
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Events accepted. `accepted` is the number of events that passed per-event validation and were counted; events for surveys that don't belong to the project are dropped silently.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SurveyEventsResponse"
                }
              }
            }
          },
          "403": {
            "description": "Origin not allowed for this project."
          },
          "404": {
            "description": "Project not found for `project_key`."
          },
          "413": {
            "description": "More than 32 events in the batch."
          }
        },
        "tags": [
          "Surveys"
        ]
      }
    },
    "/users/upsert": {
      "post": {
        "operationId": "upsertCustomerUser",
        "summary": "Upsert a customer user",
        "description": "Register or update one of your users so SeggWat can schedule time-based lifecycle surveys (chiefly trial-ending-soon) at the right moment. Idempotent on (project_id, user_ref) — re-calling with a new trial_ends_at reschedules; passing null cancels pending schedules.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "project_id",
                  "user_ref"
                ],
                "properties": {
                  "project_id": {
                    "type": "string",
                    "description": "Project this user belongs to. Must be owned by the API key's organization.",
                    "example": "507f1f77bcf86cd799439011"
                  },
                  "user_ref": {
                    "type": "string",
                    "description": "Stable identifier for this user in your system. Echoes back as `submitted_by` on survey responses.",
                    "example": "user_abc123"
                  },
                  "email": {
                    "type": "string",
                    "nullable": true,
                    "description": "Optional contact email. Stored so the dashboard can correlate in-app survey responses with an address. SeggWat does not send anything to it — survey magic-link URLs are returned in the lifecycle/dispatch response for you to relay via your own channel. Pass null to clear.",
                    "example": "alex@acme.com"
                  },
                  "trial_ends_at": {
                    "type": "string",
                    "format": "date-time",
                    "nullable": true,
                    "description": "ISO-8601 timestamp for trial expiry. Setting this enables trial-ending-soon scheduling; null cancels.",
                    "example": "2026-06-15T00:00:00Z"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "User upserted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "project_id": {
                      "type": "string"
                    },
                    "user_ref": {
                      "type": "string"
                    },
                    "email": {
                      "type": "string",
                      "nullable": true
                    },
                    "trial_ends_at": {
                      "type": "string",
                      "format": "date-time",
                      "nullable": true
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation failed (empty user_ref, malformed project_id)."
          },
          "401": {
            "description": "Missing or invalid API key."
          },
          "403": {
            "description": "API key's org doesn't own the project."
          },
          "404": {
            "description": "Project not found."
          }
        },
        "tags": [
          "Lifecycle"
        ]
      }
    },
    "/projects/{project_id}/surveys": {
      "get": {
        "operationId": "listProjectSurveys",
        "summary": "List project surveys",
        "description": "List every survey on the project (all statuses, including archived) with a denormalized response count per survey.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "responses": {
          "200": {
            "description": "Array of surveys with response counts.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/SurveyListItem"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation error.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Surveys"
        ]
      },
      "post": {
        "operationId": "createProjectSurvey",
        "summary": "Create survey from template",
        "description": "Create a new survey from a canonical template. The survey starts in `draft` status — use `PATCH .../status` to flip it to `live` before the widget serves it. Returns 400 when the project has reached the 10-survey limit.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Template to instantiate.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateSurveyRequest"
              },
              "examples": {
                "nps": {
                  "summary": "NPS survey",
                  "value": {
                    "template": "nps"
                  }
                },
                "csat": {
                  "summary": "CSAT survey",
                  "value": {
                    "template": "csat"
                  }
                },
                "blank": {
                  "summary": "Blank survey",
                  "value": {
                    "template": "blank"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Survey created in draft status.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Survey"
                }
              }
            }
          },
          "400": {
            "description": "Validation error or project survey cap reached (10 surveys).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                },
                "examples": {
                  "capReached": {
                    "summary": "Survey limit reached",
                    "value": {
                      "error": "bad_request",
                      "message": "Project has reached the maximum number of surveys (10)"
                    }
                  }
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Surveys"
        ]
      }
    },
    "/projects/{project_id}/surveys/{survey_id}": {
      "get": {
        "operationId": "getProjectSurvey",
        "summary": "Get survey",
        "description": "Fetch a single survey by ID, scoped to the project. Returns 404 when the survey does not belong to the given project.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "survey_id",
            "in": "path",
            "required": true,
            "description": "MongoDB ObjectId of the survey",
            "schema": {
              "type": "string"
            },
            "example": "6630f1c7c2b3a40a1e9e1b22"
          }
        ],
        "responses": {
          "200": {
            "description": "The requested survey.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Survey"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or survey not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Surveys"
        ]
      }
    },
    "/projects/{project_id}/surveys/{survey_id}/stats": {
      "get": {
        "operationId": "getProjectSurveyStats",
        "summary": "Get survey analytics",
        "description": "Aggregate per-question analytics for a single survey: response counts, NPS score, choice distributions, scale averages, and a response timeline.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "survey_id",
            "in": "path",
            "required": true,
            "description": "MongoDB ObjectId of the survey",
            "schema": {
              "type": "string"
            },
            "example": "6630f1c7c2b3a40a1e9e1b22"
          }
        ],
        "responses": {
          "200": {
            "description": "Per-question aggregated statistics for the survey.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SurveyResponseStats"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or survey not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Surveys"
        ]
      }
    },
    "/projects/{project_id}/surveys/{survey_id}/status": {
      "patch": {
        "operationId": "setProjectSurveyStatus",
        "summary": "Update survey status",
        "description": "Change a survey's lifecycle status. Flipping to `live` enables dispatch and widget serving. Flipping to `paused` suppresses triggers without deleting the definition. Returns the updated survey.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "survey_id",
            "in": "path",
            "required": true,
            "description": "MongoDB ObjectId of the survey",
            "schema": {
              "type": "string"
            },
            "example": "6630f1c7c2b3a40a1e9e1b22"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "New lifecycle status.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetSurveyStatusRequest"
              },
              "examples": {
                "goLive": {
                  "summary": "Publish the survey",
                  "value": {
                    "status": "live"
                  }
                },
                "pause": {
                  "summary": "Pause without deleting",
                  "value": {
                    "status": "paused"
                  }
                },
                "archive": {
                  "summary": "Soft-delete",
                  "value": {
                    "status": "archived"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated survey.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Survey"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or survey not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Surveys"
        ]
      }
    },
    "/lifecycle/dispatch": {
      "post": {
        "operationId": "dispatchLifecycleEvent",
        "summary": "Fire a lifecycle event",
        "description": "Fire a lifecycle event (trial_expired, subscription_cancelled, onboarding_completed, custom, etc.) from your backend. SeggWat matches the event against live lifecycle-triggered surveys on the project, creates one SurveyInvitation per match (subject to each survey's cooldown and sample-rate), and returns the magic-link URLs in `created_invitations` so you can relay them via your own notification pipeline (email, SMS, push). SeggWat does not deliver these URLs itself.\n\nFor time-based events that haven't happened yet (trial_ending_soon), use `/users/upsert` instead — SeggWat schedules those itself.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "project_id",
                  "event",
                  "user_ref"
                ],
                "properties": {
                  "project_id": {
                    "type": "string",
                    "description": "Project this event belongs to. Must be owned by the API key's organization.",
                    "example": "507f1f77bcf86cd799439011"
                  },
                  "event": {
                    "description": "Lifecycle event to fire. Snake-case for built-in variants; `{\"custom\": \"name\"}` for customer-defined events.",
                    "oneOf": [
                      {
                        "type": "string",
                        "enum": [
                          "trial_expired",
                          "trial_cancelled",
                          "subscription_cancelled",
                          "subscription_downgraded",
                          "onboarding_completed",
                          "first_feedback_submitted"
                        ]
                      },
                      {
                        "type": "object",
                        "required": [
                          "custom"
                        ],
                        "properties": {
                          "custom": {
                            "type": "string"
                          }
                        }
                      }
                    ]
                  },
                  "user_ref": {
                    "type": "string",
                    "description": "Customer-managed user identifier (their internal id / email / etc).",
                    "example": "user_abc123"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Event dispatched. Counts describe what happened.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "matched_surveys": {
                      "type": "integer",
                      "description": "Live surveys subscribed to this event."
                    },
                    "created_count": {
                      "type": "integer",
                      "description": "Invitations newly created. Equals `created_invitations.length`."
                    },
                    "suppressed_by_cooldown_count": {
                      "type": "integer",
                      "description": "Matched surveys skipped because this user is still inside the cooldown window."
                    },
                    "suppressed_by_sample_count": {
                      "type": "integer",
                      "description": "Matched surveys skipped because the per-survey sample_rate roll missed. Independent of cooldown — a sample miss writes no invitation, so a re-fired event gets a fresh roll."
                    },
                    "errored_count": {
                      "type": "integer",
                      "description": "Surveys that errored mid-dispatch."
                    },
                    "created_invitations": {
                      "type": "array",
                      "description": "One entry per invitation created on this call. Hand the magic_link_url to your own notification pipeline (email, SMS, push) — SeggWat does not deliver it.",
                      "items": {
                        "type": "object",
                        "required": [
                          "survey_id",
                          "user_ref",
                          "magic_link_url",
                          "expires_at"
                        ],
                        "properties": {
                          "survey_id": {
                            "type": "string",
                            "description": "Stable id of the parent survey."
                          },
                          "user_ref": {
                            "type": "string",
                            "description": "Echoed back from the dispatch request."
                          },
                          "magic_link_url": {
                            "type": "string",
                            "format": "uri",
                            "description": "Direct link to the SeggWat-hosted respond page. Single-survey token — treat like a password and only ship to the targeted user."
                          },
                          "expires_at": {
                            "type": "string",
                            "format": "date-time",
                            "description": "After this point the link 410s. Default lifetime is 30 days."
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation failed (empty user_ref)."
          },
          "401": {
            "description": "Missing or invalid API key."
          },
          "403": {
            "description": "API key's org doesn't own the project."
          },
          "404": {
            "description": "Project not found."
          }
        },
        "tags": [
          "Lifecycle"
        ]
      }
    },
    "/projects/{project_id}/changelog": {
      "get": {
        "operationId": "listProjectChangelog",
        "summary": "List changelog entries",
        "description": "Every changelog entry on the project (all statuses: draft, published, hidden), newest first. Use this to review synced drafts before publishing.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "component",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Narrow the list to one component slug from the project's registry.",
            "example": "cli"
          }
        ],
        "responses": {
          "200": {
            "description": "All changelog entries, newest first.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ChangelogEntry"
                  }
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Changelog"
        ]
      },
      "post": {
        "operationId": "createChangelogEntry",
        "summary": "Create a changelog entry",
        "description": "Create a hand-authored entry (`source = manual`). Lands as a draft unless `publish` is set. Set `published_at` to backdate entries when importing existing changelog history.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangelogCreateRequest"
              },
              "examples": {
                "draft": {
                  "summary": "Draft for review",
                  "value": {
                    "title": "Dark mode",
                    "body": "The dashboard now follows your OS theme.",
                    "category": "added"
                  }
                },
                "publishNow": {
                  "summary": "Publish immediately with a version",
                  "value": {
                    "title": "Faster exports",
                    "body": "CSV exports are ~10x faster.",
                    "version": "v1.4.0",
                    "category": "improved",
                    "publish": true
                  }
                },
                "backdatedImport": {
                  "summary": "Import a historical entry",
                  "value": {
                    "title": "Initial release",
                    "body": "Hello world.",
                    "publish": true,
                    "published_at": "2024-03-15"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The created entry.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChangelogEntry"
                }
              }
            }
          },
          "400": {
            "description": "Validation error (empty title, invalid `published_at`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Changelog"
        ]
      }
    },
    "/projects/{project_id}/changelog/{entry_id}": {
      "get": {
        "operationId": "getChangelogEntry",
        "summary": "Get a changelog entry",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "entry_id",
            "in": "path",
            "required": true,
            "description": "MongoDB ObjectId of the changelog entry",
            "schema": {
              "type": "string"
            },
            "example": "6630f1c7c2b3a40a1e9e1b33"
          }
        ],
        "responses": {
          "200": {
            "description": "The entry.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChangelogEntry"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or entry not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Changelog"
        ]
      },
      "patch": {
        "operationId": "updateChangelogEntry",
        "summary": "Update a changelog entry",
        "description": "Replace the entry's editable content (title, Markdown body, version, category). Full-document semantics: omitted `version`/`category` are cleared. Lifecycle changes go through the `/status` endpoint.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "entry_id",
            "in": "path",
            "required": true,
            "description": "MongoDB ObjectId of the changelog entry",
            "schema": {
              "type": "string"
            },
            "example": "6630f1c7c2b3a40a1e9e1b33"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ChangelogUpdateRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated entry.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChangelogEntry"
                }
              }
            }
          },
          "400": {
            "description": "Validation error (empty title).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or entry not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Changelog"
        ]
      },
      "delete": {
        "operationId": "deleteChangelogEntry",
        "summary": "Delete a changelog entry",
        "description": "Permanently delete an entry. To remove it from the public board without losing it, set its status to `hidden` instead.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "entry_id",
            "in": "path",
            "required": true,
            "description": "MongoDB ObjectId of the changelog entry",
            "schema": {
              "type": "string"
            },
            "example": "6630f1c7c2b3a40a1e9e1b33"
          }
        ],
        "responses": {
          "204": {
            "description": "Entry deleted."
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Changelog"
        ]
      }
    },
    "/projects/{project_id}/changelog/{entry_id}/status": {
      "patch": {
        "operationId": "setChangelogEntryStatus",
        "summary": "Update changelog entry status",
        "description": "Change an entry's lifecycle status. `published` puts the entry live on the public board — this is the review gate for drafts from GitHub release sync and completed ideas. First publish stamps `published_at` (the display date) when not set explicitly; re-publishing keeps the original date.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "entry_id",
            "in": "path",
            "required": true,
            "description": "MongoDB ObjectId of the changelog entry",
            "schema": {
              "type": "string"
            },
            "example": "6630f1c7c2b3a40a1e9e1b33"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "New lifecycle status.",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/SetChangelogStatusRequest"
              },
              "examples": {
                "publish": {
                  "summary": "Publish to the public board",
                  "value": {
                    "status": "published"
                  }
                },
                "unpublish": {
                  "summary": "Back to draft",
                  "value": {
                    "status": "draft"
                  }
                },
                "hide": {
                  "summary": "Soft-hide",
                  "value": {
                    "status": "hidden"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The updated entry.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ChangelogEntry"
                }
              }
            }
          },
          "403": {
            "description": "Access denied - API key does not have access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project or entry not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Changelog"
        ]
      }
    },
    "/agent/{project_key}/discovery.json": {
      "get": {
        "operationId": "getAgentFeedbackDiscovery",
        "tags": [
          "Agent Feedback"
        ],
        "summary": "Discovery document",
        "description": "The document customers host on their own domain at `/.well-known/agent-feedback.json`. All URLs are absolute. No authentication. Wire-compatible with the agent feedback protocol (discovery at `/.well-known/agent-feedback.json`).",
        "security": [],
        "parameters": [
          {
            "name": "project_key",
            "in": "path",
            "required": true,
            "description": "The project key (UUID) shown in Project Settings. Agent reports must be enabled for the project.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Discovery document (cached 5 minutes).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentDiscovery"
                }
              }
            }
          },
          "404": {
            "description": "Project not found or agent reports are not enabled for it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentError"
                },
                "example": {
                  "error": "not_found",
                  "message": "Project not found or agent reports are not enabled"
                }
              }
            }
          }
        }
      }
    },
    "/agent/{project_key}/policy": {
      "get": {
        "operationId": "getAgentFeedbackPolicy",
        "tags": [
          "Agent Feedback"
        ],
        "summary": "Submission policy",
        "description": "Accepted categories, severity levels, evidence types, surface kinds and limits. No authentication. Wire-compatible with the agent feedback protocol (discovery at `/.well-known/agent-feedback.json`).",
        "security": [],
        "parameters": [
          {
            "name": "project_key",
            "in": "path",
            "required": true,
            "description": "The project key (UUID) shown in Project Settings. Agent reports must be enabled for the project.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Policy document (cached 5 minutes).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentPolicy"
                }
              }
            }
          },
          "404": {
            "description": "Project not found or agent reports are not enabled for it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentError"
                },
                "example": {
                  "error": "not_found",
                  "message": "Project not found or agent reports are not enabled"
                }
              }
            }
          }
        }
      }
    },
    "/agent/{project_key}/feedback": {
      "post": {
        "operationId": "submitAgentFeedback",
        "tags": [
          "Agent Feedback"
        ],
        "summary": "Submit an agent report",
        "description": "Files a structured report. It lands in the project's feedback inbox with source `AgentReport`; the category maps to a feedback type (bug/quality_degradation → Bug, feature_gap → Feature, friction/docs_mismatch → Improvement, other → Other). Rate limited with the other public submit endpoints (bursts of 20, about 60/hour per IP). No authentication. Wire-compatible with the agent feedback protocol (discovery at `/.well-known/agent-feedback.json`).",
        "security": [],
        "parameters": [
          {
            "name": "project_key",
            "in": "path",
            "required": true,
            "description": "The project key (UUID) shown in Project Settings. Agent reports must be enabled for the project.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AgentFeedbackInput"
              },
              "example": {
                "reporter": {
                  "agent_vendor": "anthropic",
                  "agent_product": "claude-code",
                  "agent_version": "2.1.0"
                },
                "subject": {
                  "surface": "GET /v2/orders",
                  "domain": "api.acme.com",
                  "kind": "api_endpoint"
                },
                "signal": {
                  "category": "docs_mismatch",
                  "severity": "medium",
                  "confidence": 0.9,
                  "reproducibility": "always"
                },
                "content": {
                  "title": "Docs say X-API-Key, but /v2/orders only accepts Authorization: Bearer",
                  "summary": "The auth page says to send X-API-Key. GET /v2/orders returns 401 with it and 200 with Authorization: Bearer.",
                  "hypothesis": "v2 dropped X-API-Key and the auth page still documents v1."
                },
                "evidence": [
                  {
                    "type": "http_summary",
                    "content": "GET /v2/orders\nX-API-Key: [REDACTED]\n-> 401",
                    "redacted": true
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Report accepted. The receipt id is the feedback item's id.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentReceiptResponse"
                },
                "example": {
                  "receipt": {
                    "id": "66f5a1c2e4b0a1b2c3d4e5f6",
                    "feedback_id": "66f5a1c2e4b0a1b2c3d4e5f6",
                    "status": "accepted",
                    "evidence_ids": [],
                    "created_at": "2026-09-27T10:15:30Z"
                  }
                }
              }
            }
          },
          "400": {
            "description": "Validation failed. Every failing field is listed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentValidationError"
                },
                "example": {
                  "error": "validation_failed",
                  "errors": [
                    {
                      "field": "signal.confidence",
                      "error": "out_of_range",
                      "message": "signal.confidence must be between 0 and 1"
                    }
                  ]
                }
              }
            }
          },
          "404": {
            "description": "Project not found or agent reports are not enabled for it.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentError"
                },
                "example": {
                  "error": "not_found",
                  "message": "Project not found or agent reports are not enabled"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded."
          }
        }
      }
    },
    "/agent/{project_key}/receipts/{id}": {
      "get": {
        "operationId": "getAgentFeedbackReceipt",
        "tags": [
          "Agent Feedback"
        ],
        "summary": "Look up a receipt",
        "description": "Status of a submitted report. `status` is `accepted` until the team archives the item, then `rejected`. Only reports filed through this endpoint for this project resolve. No authentication. Wire-compatible with the agent feedback protocol (discovery at `/.well-known/agent-feedback.json`).",
        "security": [],
        "parameters": [
          {
            "name": "project_key",
            "in": "path",
            "required": true,
            "description": "The project key (UUID) shown in Project Settings. Agent reports must be enabled for the project.",
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The receipt id returned on submit.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Receipt.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentReceiptLookup"
                },
                "example": {
                  "data": {
                    "id": "66f5a1c2e4b0a1b2c3d4e5f6",
                    "feedback_id": "66f5a1c2e4b0a1b2c3d4e5f6",
                    "observation_id": null,
                    "status": "accepted",
                    "quality_score": null,
                    "duplicate_of": null,
                    "created_at": "2026-09-27T10:15:30Z"
                  }
                }
              }
            }
          },
          "404": {
            "description": "Receipt not found, or the project is missing / has agent reports disabled.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AgentError"
                }
              }
            }
          }
        }
      }
    },
    "/projects/{project_id}/install-status": {
      "get": {
        "operationId": "getProjectInstallStatus",
        "summary": "Get widget install status",
        "description": "When each widget kind first submitted to this project. A non-null timestamp proves the embed fired with the right project key at least once.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "name": "project_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "First-submission timestamps, null where nothing has arrived yet.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/WidgetInstallStatus"
                }
              }
            }
          },
          "401": {
            "description": "Authentication failed - invalid or missing API key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "No access to this project.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "Project not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        },
        "tags": [
          "Projects"
        ]
      }
    },
    "/projects/{project_id}/inbox": {
      "get": {
        "operationId": "listInbox",
        "summary": "List the project inbox",
        "tags": [
          "Inbox"
        ],
        "description": "Everything that needs the team in one list, sorted with items waiting on you first, then newest. `open` lists what is still in play (including answered conversations); `done` lists closed conversations and replied contact messages. Requires `feedback:read`.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "filter",
            "in": "query",
            "description": "Item types to include",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "chat",
                "feedback",
                "contact",
                "ideas"
              ],
              "default": "all"
            }
          },
          {
            "name": "view",
            "in": "query",
            "description": "Open work or finished history",
            "schema": {
              "type": "string",
              "enum": [
                "open",
                "done"
              ],
              "default": "open"
            }
          },
          {
            "name": "page",
            "in": "query",
            "description": "Page number (1-indexed)",
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1
            }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Items per page",
            "schema": {
              "type": "integer",
              "default": 30,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "q",
            "in": "query",
            "description": "Keep items whose person or snippet contains this text (case-insensitive)",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "One page of inbox items",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboxPage"
                },
                "example": {
                  "items": [
                    {
                      "kind": "chat",
                      "id": "507f1f77bcf86cd799439011",
                      "person": "mia@example.com",
                      "snippet": "How do I export all my feedback as CSV?",
                      "at": "2026-10-28T09:12:00Z",
                      "needs_reply": true
                    },
                    {
                      "kind": "idea_comments",
                      "id": "507f1f77bcf86cd799439055",
                      "person": "lena@example.com",
                      "snippet": "On \"Dark mode\": Any update on this?",
                      "at": "2026-10-28T08:40:00Z",
                      "needs_reply": true
                    }
                  ],
                  "has_more": false
                }
              }
            }
          },
          "400": {
            "description": "Unknown `filter` or `view` value"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key's organization can't access this project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/projects/{project_id}/inbox/counts": {
      "get": {
        "operationId": "getInboxCounts",
        "summary": "Count inbox items waiting on the team",
        "tags": [
          "Inbox"
        ],
        "description": "How many open items wait on the team, per type — for badges. Counts exactly the items `GET /inbox` marks `needs_reply`. Requires `feedback:read`.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          }
        ],
        "responses": {
          "200": {
            "description": "Waiting counts per type",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/InboxCounts"
                },
                "example": {
                  "chat": 1,
                  "feedback": 8,
                  "contact": 6,
                  "ideas": 2
                }
              }
            }
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key's organization can't access this project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    },
    "/projects/{project_id}/inbox/{kind}/{item_id}": {
      "patch": {
        "operationId": "updateInboxItem",
        "summary": "Delete an inbox item or undo that",
        "tags": [
          "Inbox"
        ],
        "description": "Soft delete: `archived: true` hides the item from every inbox list and count; `false` brings it back. Works for `chat`, `feedback_thread`, `feedback` and `contact`; ideas are approved, rejected or marked handled instead (400). A new end-user message brings a deleted conversation back. Requires `feedback:write`.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "kind",
            "in": "path",
            "required": true,
            "description": "The item's inbox kind",
            "schema": {
              "type": "string",
              "enum": [
                "chat",
                "feedback_thread",
                "feedback",
                "contact"
              ]
            }
          },
          {
            "name": "item_id",
            "in": "path",
            "required": true,
            "description": "The item's id, as listed by `GET /inbox`",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "archived"
                ],
                "properties": {
                  "archived": {
                    "type": "boolean",
                    "description": "`true` deletes (hides), `false` restores"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "204": {
            "description": "Updated"
          },
          "400": {
            "description": "Ideas can't be deleted from the inbox"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key's organization can't access this project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such item in this project"
          }
        }
      }
    },
    "/projects/{project_id}/ideas/{idea_id}/comments/seen": {
      "post": {
        "operationId": "markIdeaCommentsSeen",
        "summary": "Mark an idea's new comments as handled",
        "tags": [
          "Ideas",
          "Inbox"
        ],
        "description": "Takes an idea's new visitor comments out of the inbox without replying. A newer visitor comment brings the idea back. Posting a team reply has the same effect. Requires `idea:write`.",
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/ProjectIdPath"
          },
          {
            "name": "idea_id",
            "in": "path",
            "required": true,
            "description": "Unique identifier of the idea",
            "schema": {
              "type": "string"
            },
            "example": "507f1f77bcf86cd799439055"
          }
        ],
        "responses": {
          "204": {
            "description": "Marked as handled"
          },
          "401": {
            "description": "Missing or invalid API key",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "403": {
            "description": "The key's organization can't access this project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          },
          "404": {
            "description": "No such idea in this project",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Error"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "HealthStatus": {
        "type": "object",
        "description": "Basic health status response",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "ok",
              "degraded",
              "error"
            ],
            "description": "Current health status of the service"
          }
        },
        "required": [
          "status"
        ]
      },
      "FeedbackSubmission": {
        "type": "object",
        "description": "Feedback submission request",
        "properties": {
          "project_key": {
            "type": "string",
            "format": "uuid",
            "description": "Unique identifier for the project (UUID format)",
            "example": "550e8400-e29b-41d4-a716-446655440000"
          },
          "message": {
            "type": "string",
            "minLength": 1,
            "description": "The feedback message text (cannot be empty)",
            "example": "This is a great product! I love the new features."
          },
          "path": {
            "type": "string",
            "pattern": "^/.*",
            "description": "Optional URL path where the feedback was generated (must start with /)",
            "example": "/dashboard/settings"
          },
          "version": {
            "type": "string",
            "description": "Optional application version to track feedback against specific releases",
            "example": "1.2.3"
          },
          "submitted_by": {
            "type": "string",
            "maxLength": 255,
            "pattern": "^[a-zA-Z0-9_-]+$",
            "description": "Optional user identifier from your system (GDPR-compliant reference)",
            "example": "user_12345"
          },
          "source": {
            "$ref": "#/components/schemas/FeedbackSource"
          },
          "social_url": {
            "type": "string",
            "format": "uri",
            "description": "Tweet URL (required when source is SocialShare, must be a valid twitter.com or x.com status URL)",
            "example": "https://x.com/user/status/1234567890"
          }
        },
        "required": [
          "project_key",
          "message"
        ]
      },
      "FeedbackCreateRequest": {
        "type": "object",
        "description": "Request body for creating feedback via API key authentication",
        "properties": {
          "message": {
            "type": "string",
            "minLength": 1,
            "description": "The feedback message text (cannot be empty)",
            "example": "Customer reported slow loading times on mobile devices"
          },
          "type": {
            "$ref": "#/components/schemas/FeedbackType"
          },
          "path": {
            "type": "string",
            "description": "Optional URL path where the feedback relates to",
            "example": "/dashboard/settings"
          },
          "version": {
            "type": "string",
            "description": "Optional application version to track feedback against specific releases",
            "example": "2.1.0"
          },
          "submitted_by": {
            "type": "string",
            "description": "Optional user identifier who submitted the feedback",
            "example": "user-abc-123"
          }
        },
        "required": [
          "message"
        ]
      },
      "SubmissionResult": {
        "type": "object",
        "description": "Result of feedback submission",
        "properties": {
          "status": {
            "type": "string",
            "enum": [
              "received",
              "queued",
              "stored"
            ],
            "description": "Status of the feedback submission"
          }
        },
        "required": [
          "status"
        ]
      },
      "Error": {
        "type": "object",
        "description": "Error response",
        "properties": {
          "error": {
            "type": "string",
            "description": "Error type or code",
            "example": "validation_error"
          },
          "message": {
            "type": "string",
            "description": "Human-readable error message",
            "example": "project_key is required"
          }
        },
        "required": [
          "error",
          "message"
        ]
      },
      "FeedbackStatus": {
        "type": "string",
        "description": "Status of a feedback item",
        "enum": [
          "New",
          "Active",
          "Hold",
          "Closed",
          "Resolved"
        ]
      },
      "FeedbackType": {
        "type": "string",
        "description": "Type/category of feedback",
        "enum": [
          "Bug",
          "Feature",
          "Praise",
          "Question",
          "Improvement",
          "Other"
        ]
      },
      "FeedbackSource": {
        "type": "string",
        "description": "Source where the feedback originated",
        "enum": [
          "Widget",
          "Manual",
          "Mintlify",
          "Stripe",
          "Polar",
          "SocialShare",
          "AgentReport"
        ]
      },
      "Feedback": {
        "type": "object",
        "description": "A feedback item",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the feedback item",
            "example": "507f1f77bcf86cd799439011"
          },
          "project_id": {
            "type": "string",
            "description": "The project this feedback belongs to",
            "example": "550e8400-e29b-41d4-a716-446655440000"
          },
          "message": {
            "type": "string",
            "description": "The feedback message content",
            "example": "The dashboard loads slowly on mobile devices"
          },
          "status": {
            "$ref": "#/components/schemas/FeedbackStatus"
          },
          "type": {
            "$ref": "#/components/schemas/FeedbackType"
          },
          "source": {
            "$ref": "#/components/schemas/FeedbackSource"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp when the feedback was created",
            "example": "2024-01-15T10:30:00Z"
          },
          "path": {
            "type": "string",
            "description": "The URL path where the feedback was submitted",
            "example": "/dashboard"
          },
          "version": {
            "type": "string",
            "description": "Application version when feedback was submitted",
            "example": "1.2.3"
          },
          "archived": {
            "type": "boolean",
            "description": "Whether the feedback has been archived",
            "example": false
          },
          "submitted_by": {
            "type": "string",
            "description": "User identifier from the customer's system",
            "example": "user_12345"
          },
          "social_url": {
            "type": "string",
            "description": "Tweet URL for social share feedback (only present when source is SocialShare)",
            "example": "https://x.com/user/status/1234567890"
          }
        },
        "required": [
          "id",
          "project_id",
          "message",
          "status",
          "type",
          "source",
          "created_at",
          "archived"
        ]
      },
      "FeedbackUpdate": {
        "type": "object",
        "description": "Fields to update on a feedback item. At least one field must be provided.",
        "properties": {
          "message": {
            "type": "string",
            "minLength": 1,
            "description": "Updated feedback message content",
            "example": "Updated feedback text"
          },
          "type": {
            "$ref": "#/components/schemas/FeedbackType"
          },
          "status": {
            "$ref": "#/components/schemas/FeedbackStatus"
          }
        }
      },
      "PaginationInfo": {
        "type": "object",
        "description": "Pagination metadata",
        "properties": {
          "page": {
            "type": "integer",
            "description": "Current page number",
            "example": 1
          },
          "limit": {
            "type": "integer",
            "description": "Items per page",
            "example": 20
          },
          "total": {
            "type": "integer",
            "description": "Total number of items matching the filters",
            "example": 42
          },
          "total_pages": {
            "type": "integer",
            "description": "Total number of pages available",
            "example": 3
          }
        },
        "required": [
          "page",
          "limit",
          "total",
          "total_pages"
        ]
      },
      "FeedbackListResponse": {
        "type": "object",
        "description": "Paginated list of feedback items",
        "properties": {
          "feedback": {
            "type": "array",
            "description": "Array of feedback items",
            "items": {
              "$ref": "#/components/schemas/Feedback"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/PaginationInfo"
          }
        },
        "required": [
          "feedback",
          "pagination"
        ]
      },
      "Project": {
        "type": "object",
        "description": "A project with metadata",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the project (MongoDB ObjectId)",
            "example": "507f1f77bcf86cd799439011"
          },
          "key": {
            "type": "string",
            "format": "uuid",
            "description": "Project key used for widget configuration",
            "example": "550e8400-e29b-41d4-a716-446655440000"
          },
          "name": {
            "type": "string",
            "description": "Human-readable project name",
            "example": "My Web App"
          },
          "description": {
            "type": "string",
            "description": "Project description",
            "example": "Main production application"
          },
          "allowed_origins": {
            "type": "array",
            "description": "List of allowed origins for widget submissions",
            "items": {
              "type": "string"
            },
            "example": [
              "https://example.com",
              "https://app.example.com"
            ]
          },
          "org_id": {
            "type": "string",
            "description": "Organization that owns this project",
            "example": "507f1f77bcf86cd799439022"
          },
          "feedback_count": {
            "type": "integer",
            "description": "Total number of feedback items for this project",
            "example": 142
          }
        },
        "required": [
          "id",
          "key",
          "name",
          "description",
          "allowed_origins",
          "org_id",
          "feedback_count"
        ]
      },
      "FeedbackCounts": {
        "type": "object",
        "description": "Aggregated feedback counts for a project",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of feedback items",
            "example": 142
          },
          "current_month": {
            "type": "integer",
            "description": "Number of feedback items submitted in the current calendar month",
            "example": 18
          },
          "last_month": {
            "type": "integer",
            "description": "Number of feedback items submitted in the previous calendar month",
            "example": 24
          }
        },
        "required": [
          "total",
          "current_month",
          "last_month"
        ]
      },
      "IdeaCounts": {
        "type": "object",
        "description": "Aggregated idea counts for a project",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of non-archived ideas",
            "example": 37
          },
          "pending": {
            "type": "integer",
            "description": "Number of ideas with Pending status awaiting review",
            "example": 5
          }
        },
        "required": [
          "total",
          "pending"
        ]
      },
      "MessageCounts": {
        "type": "object",
        "description": "Aggregated contact message counts for a project",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of non-archived contact messages",
            "example": 9
          }
        },
        "required": [
          "total"
        ]
      },
      "FeedbackTypeCounts": {
        "type": "object",
        "description": "Feedback item counts broken down by type",
        "properties": {
          "bug": {
            "type": "integer",
            "description": "Number of bug reports",
            "example": 32
          },
          "feature": {
            "type": "integer",
            "description": "Number of feature requests",
            "example": 55
          },
          "praise": {
            "type": "integer",
            "description": "Number of praise items",
            "example": 21
          },
          "question": {
            "type": "integer",
            "description": "Number of questions",
            "example": 14
          },
          "improvement": {
            "type": "integer",
            "description": "Number of improvement suggestions",
            "example": 12
          },
          "other": {
            "type": "integer",
            "description": "Number of feedback items with type Other",
            "example": 8
          }
        },
        "required": [
          "bug",
          "feature",
          "praise",
          "question",
          "improvement",
          "other"
        ]
      },
      "FeedbackStatusCounts": {
        "type": "object",
        "description": "Feedback item counts broken down by status",
        "properties": {
          "new": {
            "type": "integer",
            "description": "Number of feedback items with status New",
            "example": 41
          },
          "active": {
            "type": "integer",
            "description": "Number of feedback items with status Active",
            "example": 28
          },
          "hold": {
            "type": "integer",
            "description": "Number of feedback items with status Hold",
            "example": 7
          },
          "closed": {
            "type": "integer",
            "description": "Number of feedback items with status Closed",
            "example": 33
          },
          "resolved": {
            "type": "integer",
            "description": "Number of feedback items with status Resolved",
            "example": 18
          }
        },
        "required": [
          "new",
          "active",
          "hold",
          "closed",
          "resolved"
        ]
      },
      "FeedbackSummaryStats": {
        "type": "object",
        "description": "Aggregated feedback statistics including monthly counts and breakdowns by type and status",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of feedback items",
            "example": 142
          },
          "current_month": {
            "type": "integer",
            "description": "Number of feedback items submitted in the current calendar month",
            "example": 18
          },
          "last_month": {
            "type": "integer",
            "description": "Number of feedback items submitted in the previous calendar month",
            "example": 24
          },
          "by_type": {
            "$ref": "#/components/schemas/FeedbackTypeCounts"
          },
          "by_status": {
            "$ref": "#/components/schemas/FeedbackStatusCounts"
          }
        },
        "required": [
          "total",
          "current_month",
          "last_month",
          "by_type",
          "by_status"
        ]
      },
      "RatingSummaryStats": {
        "type": "object",
        "description": "Aggregated rating statistics across all rating types for a project",
        "properties": {
          "helpful": {
            "$ref": "#/components/schemas/HelpfulStats"
          },
          "star": {
            "$ref": "#/components/schemas/StarStats"
          },
          "nps": {
            "$ref": "#/components/schemas/NpsStats"
          }
        },
        "required": [
          "helpful",
          "star",
          "nps"
        ]
      },
      "FeedbackSummaryItem": {
        "type": "object",
        "description": "A brief summary of a single feedback item, suitable for list views",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier of the feedback item",
            "example": "507f1f77bcf86cd799439031"
          },
          "message_preview": {
            "type": "string",
            "description": "Truncated preview of the feedback message",
            "example": "The export button doesn't work in Firefox when I try to download..."
          },
          "feedback_type": {
            "type": "string",
            "description": "Type of the feedback item",
            "example": "Bug"
          },
          "path": {
            "type": "string",
            "nullable": true,
            "description": "Page path where the feedback was submitted; null if not captured",
            "example": "/dashboard/reports"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp of when the feedback was submitted",
            "example": "2024-01-15T14:32:00Z"
          }
        },
        "required": [
          "id",
          "message_preview",
          "feedback_type",
          "created_at"
        ]
      },
      "ProjectSummary": {
        "type": "object",
        "description": "All-in-one project overview combining project details with aggregated statistics. Designed to minimise mobile round trips.",
        "properties": {
          "project": {
            "$ref": "#/components/schemas/Project"
          },
          "feedback": {
            "$ref": "#/components/schemas/FeedbackSummaryStats"
          },
          "churn": {
            "$ref": "#/components/schemas/ChurnStats"
          },
          "ideas": {
            "$ref": "#/components/schemas/IdeaCounts"
          },
          "messages": {
            "$ref": "#/components/schemas/MessageCounts"
          },
          "ratings": {
            "$ref": "#/components/schemas/RatingSummaryStats"
          },
          "recent_feedback": {
            "type": "array",
            "description": "The most recent feedback items for the project, ordered newest first",
            "items": {
              "$ref": "#/components/schemas/FeedbackSummaryItem"
            }
          }
        },
        "required": [
          "project",
          "feedback",
          "churn",
          "ideas",
          "messages",
          "ratings",
          "recent_feedback"
        ]
      },
      "IdeaComment": {
        "type": "object",
        "description": "A single comment on an idea, from either a dashboard user or a widget end-user",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier of the comment",
            "example": "507f1f77bcf86cd799439061"
          },
          "idea_id": {
            "type": "string",
            "description": "ID of the idea this comment belongs to",
            "example": "507f1f77bcf86cd799439055"
          },
          "parent_id": {
            "type": "string",
            "nullable": true,
            "description": "ID of the parent comment for replies; null for top-level comments",
            "example": null
          },
          "body": {
            "type": "string",
            "description": "Comment text",
            "example": "Great idea! Would love this feature."
          },
          "user_id": {
            "type": "string",
            "nullable": true,
            "description": "Dashboard user ID if the comment was posted by a product team member; null otherwise",
            "example": null
          },
          "user_email": {
            "type": "string",
            "nullable": true,
            "description": "Dashboard user email if the comment was posted by a product team member; null otherwise",
            "example": null
          },
          "enduser_id": {
            "type": "string",
            "nullable": true,
            "description": "Widget end-user identifier if the comment was posted via the public widget; null otherwise",
            "example": "enduser-42"
          },
          "enduser_email": {
            "type": "string",
            "nullable": true,
            "description": "Widget end-user email if provided; null otherwise",
            "example": "alice@example.com"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "Timestamp when the comment was created",
            "example": "2024-01-15T10:30:00Z"
          },
          "archived": {
            "type": "boolean",
            "description": "Whether the comment has been soft-deleted",
            "example": false
          }
        },
        "required": [
          "id",
          "idea_id",
          "parent_id",
          "body",
          "user_id",
          "user_email",
          "enduser_id",
          "enduser_email",
          "created_at",
          "archived"
        ]
      },
      "CommentThread": {
        "type": "object",
        "description": "A top-level comment with its nested replies",
        "properties": {
          "comment": {
            "$ref": "#/components/schemas/IdeaComment"
          },
          "replies": {
            "type": "array",
            "description": "Direct replies to the top-level comment (all replies, not paginated)",
            "items": {
              "$ref": "#/components/schemas/IdeaComment"
            }
          }
        },
        "required": [
          "comment",
          "replies"
        ]
      },
      "IdeaCommentListResponse": {
        "type": "object",
        "description": "Paginated list of threaded idea comments",
        "properties": {
          "comments": {
            "type": "array",
            "description": "Array of top-level comment threads",
            "items": {
              "$ref": "#/components/schemas/CommentThread"
            }
          },
          "has_more": {
            "type": "boolean",
            "description": "Whether there are more top-level comment threads beyond this page",
            "example": false
          },
          "total": {
            "type": "integer",
            "description": "Total number of top-level comment threads for the idea",
            "example": 2
          }
        },
        "required": [
          "comments",
          "has_more",
          "total"
        ]
      },
      "ProjectListResponse": {
        "type": "object",
        "description": "List of projects",
        "properties": {
          "projects": {
            "type": "array",
            "description": "Array of project items",
            "items": {
              "$ref": "#/components/schemas/Project"
            }
          }
        },
        "required": [
          "projects"
        ]
      },
      "RatingType": {
        "type": "string",
        "description": "Type of rating",
        "enum": [
          "helpful",
          "star",
          "nps"
        ]
      },
      "StatsGroupBy": {
        "type": "string",
        "description": "Field to group statistics by",
        "enum": [
          "path",
          "version",
          "day"
        ]
      },
      "RatingValue": {
        "type": "object",
        "description": "Polymorphic rating value based on type",
        "discriminator": {
          "propertyName": "type"
        },
        "oneOf": [
          {
            "type": "object",
            "description": "Helpful rating value",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "helpful"
                ]
              },
              "value": {
                "type": "boolean",
                "description": "true for helpful, false for not helpful"
              }
            },
            "required": [
              "type",
              "value"
            ]
          },
          {
            "type": "object",
            "description": "Star rating value",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "star"
                ]
              },
              "value": {
                "type": "integer",
                "minimum": 1,
                "maximum": 10,
                "description": "Star rating value"
              },
              "max_stars": {
                "type": "integer",
                "minimum": 1,
                "maximum": 10,
                "default": 5,
                "description": "Maximum star value (default 5)"
              }
            },
            "required": [
              "type",
              "value"
            ]
          },
          {
            "type": "object",
            "description": "NPS rating value",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "nps"
                ]
              },
              "value": {
                "type": "integer",
                "minimum": 0,
                "maximum": 10,
                "description": "NPS score (0-10)"
              }
            },
            "required": [
              "type",
              "value"
            ]
          }
        ]
      },
      "RatingContext": {
        "type": "object",
        "description": "Context information for a rating",
        "properties": {
          "path": {
            "type": "string",
            "description": "The URL path where the rating was submitted",
            "example": "/docs/getting-started"
          },
          "version": {
            "type": "string",
            "description": "Application version when rating was submitted",
            "example": "1.2.3"
          },
          "submitted_by": {
            "type": "string",
            "description": "User identifier from the customer's system",
            "example": "user_12345"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Optional key-value metadata"
          }
        }
      },
      "Rating": {
        "type": "object",
        "description": "A rating item supporting multiple types (helpful, star, NPS)",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the rating item",
            "example": "507f1f77bcf86cd799439011"
          },
          "project_id": {
            "type": "string",
            "description": "The project this rating belongs to",
            "example": "507f1f77bcf86cd799439022"
          },
          "rating_type": {
            "$ref": "#/components/schemas/RatingType"
          },
          "value": {
            "$ref": "#/components/schemas/RatingValue"
          },
          "path": {
            "type": "string",
            "description": "The URL path where the rating was submitted",
            "example": "/docs/getting-started"
          },
          "version": {
            "type": "string",
            "description": "Application version when rating was submitted",
            "example": "1.2.3"
          },
          "submitted_by": {
            "type": "string",
            "description": "User identifier from the customer's system",
            "example": "user_12345"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            },
            "description": "Optional key-value metadata"
          },
          "archived": {
            "type": "boolean",
            "description": "Whether the rating has been archived",
            "example": false
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp when the rating was created",
            "example": "2024-01-15T10:30:00Z"
          }
        },
        "required": [
          "id",
          "project_id",
          "rating_type",
          "value",
          "archived",
          "created_at"
        ]
      },
      "RatingSubmission": {
        "type": "object",
        "description": "Rating submission request",
        "properties": {
          "project_key": {
            "type": "string",
            "format": "uuid",
            "description": "Unique identifier for the project (UUID format)",
            "example": "550e8400-e29b-41d4-a716-446655440000"
          },
          "value": {
            "type": "boolean",
            "description": "Rating value - true for helpful, false for not helpful",
            "example": true
          },
          "path": {
            "type": "string",
            "description": "URL path where the rating was submitted",
            "example": "/docs/getting-started"
          },
          "version": {
            "type": "string",
            "description": "Optional application version",
            "example": "1.2.3"
          },
          "submitted_by": {
            "type": "string",
            "description": "Optional user identifier from your system",
            "example": "user_12345"
          }
        },
        "required": [
          "project_key",
          "value",
          "path"
        ]
      },
      "RatingCreateRequest": {
        "type": "object",
        "description": "Request body for creating a helpful rating via API key authentication (legacy format)",
        "properties": {
          "value": {
            "type": "boolean",
            "description": "Rating value - true for helpful, false for not helpful",
            "example": true
          },
          "path": {
            "type": "string",
            "description": "Optional URL path where the rating relates to",
            "example": "/docs/getting-started"
          },
          "version": {
            "type": "string",
            "description": "Optional application version to track ratings against specific releases",
            "example": "2.1.0"
          },
          "submitted_by": {
            "type": "string",
            "description": "Optional user identifier who submitted the rating",
            "example": "user-abc-123"
          }
        },
        "required": [
          "value"
        ]
      },
      "TypedRatingCreateRequest": {
        "type": "object",
        "description": "Request body for creating a typed rating via API key authentication",
        "properties": {
          "rating": {
            "$ref": "#/components/schemas/RatingValue"
          },
          "context": {
            "$ref": "#/components/schemas/RatingContext"
          }
        },
        "required": [
          "rating"
        ]
      },
      "UnifiedRatingSubmission": {
        "type": "object",
        "description": "Unified rating submission request for widgets",
        "properties": {
          "project_key": {
            "type": "string",
            "format": "uuid",
            "description": "Unique identifier for the project (UUID format)",
            "example": "550e8400-e29b-41d4-a716-446655440000"
          },
          "rating": {
            "$ref": "#/components/schemas/RatingValue"
          },
          "context": {
            "$ref": "#/components/schemas/RatingContext"
          }
        },
        "required": [
          "project_key",
          "rating"
        ]
      },
      "RatingCreatedResponse": {
        "type": "object",
        "description": "Response for successful rating creation",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the created rating",
            "example": "507f1f77bcf86cd799439011"
          },
          "rating_type": {
            "$ref": "#/components/schemas/RatingType"
          }
        },
        "required": [
          "id",
          "rating_type"
        ]
      },
      "RatingListResponse": {
        "type": "object",
        "description": "Paginated list of rating items",
        "properties": {
          "ratings": {
            "type": "array",
            "description": "Array of rating items",
            "items": {
              "$ref": "#/components/schemas/Rating"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/PaginationInfo"
          }
        },
        "required": [
          "ratings",
          "pagination"
        ]
      },
      "HelpfulStats": {
        "type": "object",
        "description": "Aggregated helpful rating statistics",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of ratings",
            "example": 250
          },
          "helpful": {
            "type": "integer",
            "description": "Number of positive (helpful) ratings",
            "example": 215
          },
          "not_helpful": {
            "type": "integer",
            "description": "Number of negative (not helpful) ratings",
            "example": 35
          },
          "percentage": {
            "type": "number",
            "format": "double",
            "description": "Percentage of helpful ratings (0.0 - 100.0)",
            "example": 86.0
          }
        },
        "required": [
          "total",
          "helpful",
          "not_helpful",
          "percentage"
        ]
      },
      "StarStats": {
        "type": "object",
        "description": "Aggregated star rating statistics",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of ratings",
            "example": 85
          },
          "average": {
            "type": "number",
            "format": "double",
            "description": "Average star rating",
            "example": 4.2
          },
          "distribution": {
            "type": "object",
            "description": "Distribution of ratings by star value",
            "additionalProperties": {
              "type": "integer"
            },
            "example": {
              "1": 2,
              "2": 5,
              "3": 15,
              "4": 30,
              "5": 33
            }
          }
        },
        "required": [
          "total",
          "average",
          "distribution"
        ]
      },
      "NpsStats": {
        "type": "object",
        "description": "Aggregated NPS (Net Promoter Score) statistics",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of ratings",
            "example": 200
          },
          "score": {
            "type": "integer",
            "description": "NPS score (-100 to 100)",
            "example": 45
          },
          "promoters": {
            "type": "integer",
            "description": "Number of promoters (9-10)",
            "example": 120
          },
          "passives": {
            "type": "integer",
            "description": "Number of passives (7-8)",
            "example": 50
          },
          "detractors": {
            "type": "integer",
            "description": "Number of detractors (0-6)",
            "example": 30
          },
          "distribution": {
            "type": "object",
            "description": "Distribution of ratings by value (0-10)",
            "additionalProperties": {
              "type": "integer"
            }
          }
        },
        "required": [
          "total",
          "score",
          "promoters",
          "passives",
          "detractors",
          "distribution"
        ]
      },
      "RatingStats": {
        "description": "Polymorphic rating statistics based on type",
        "oneOf": [
          {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "helpful"
                    ]
                  }
                }
              },
              {
                "$ref": "#/components/schemas/HelpfulStats"
              }
            ]
          },
          {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "star"
                    ]
                  }
                }
              },
              {
                "$ref": "#/components/schemas/StarStats"
              }
            ]
          },
          {
            "allOf": [
              {
                "type": "object",
                "properties": {
                  "type": {
                    "type": "string",
                    "enum": [
                      "nps"
                    ]
                  }
                }
              },
              {
                "$ref": "#/components/schemas/NpsStats"
              }
            ]
          }
        ],
        "discriminator": {
          "propertyName": "type"
        }
      },
      "GroupedStats": {
        "type": "object",
        "description": "Rating statistics grouped by path, version, or day",
        "properties": {
          "groups": {
            "type": "object",
            "description": "Map of group key to statistics",
            "additionalProperties": {
              "$ref": "#/components/schemas/RatingStats"
            }
          }
        },
        "required": [
          "groups"
        ]
      },
      "IdeaStatus": {
        "type": "string",
        "description": "Status of an idea",
        "enum": [
          "Pending",
          "Open",
          "Planned",
          "Started",
          "Completed",
          "Declined",
          "Duplicate",
          "Rejected"
        ]
      },
      "Idea": {
        "type": "object",
        "description": "An idea submitted by a user or created via API",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the idea",
            "example": "507f1f77bcf86cd799439011"
          },
          "project_id": {
            "type": "string",
            "description": "The project this idea belongs to",
            "example": "507f1f77bcf86cd799439022"
          },
          "title": {
            "type": "string",
            "description": "Title of the idea",
            "example": "Add dark mode support"
          },
          "description": {
            "type": "string",
            "description": "Detailed description of the idea",
            "example": "Users have requested a dark theme for nighttime use to reduce eye strain"
          },
          "status": {
            "$ref": "#/components/schemas/IdeaStatus"
          },
          "tag_ids": {
            "type": "array",
            "description": "List of tag identifiers associated with this idea",
            "items": {
              "type": "string"
            },
            "example": [
              "507f1f77bcf86cd799439050"
            ]
          },
          "votes_count": {
            "type": "integer",
            "description": "Total number of votes received",
            "example": 42
          },
          "comments_count": {
            "type": "integer",
            "description": "Total number of comments on this idea",
            "example": 7
          },
          "submitted_by": {
            "type": "string",
            "nullable": true,
            "description": "User identifier from the customer's system (if provided)",
            "example": "user_12345"
          },
          "submitted_by_email": {
            "type": "string",
            "nullable": true,
            "description": "Email address of the submitter (if provided)",
            "example": "customer@example.com"
          },
          "admin_response": {
            "type": "string",
            "nullable": true,
            "description": "Public response from an admin or team member",
            "example": "Great idea! We have this on our roadmap for Q2."
          },
          "merged_into_id": {
            "type": "string",
            "nullable": true,
            "description": "ID of the idea this was merged into (if status is Duplicate)",
            "example": null
          },
          "archived": {
            "type": "boolean",
            "description": "Whether the idea has been archived",
            "example": false
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp when the idea was created",
            "example": "2024-01-15T10:30:00Z"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp when the idea was last updated",
            "example": "2024-01-20T14:00:00Z"
          }
        },
        "required": [
          "id",
          "project_id",
          "title",
          "status",
          "tag_ids",
          "votes_count",
          "comments_count",
          "archived",
          "created_at",
          "updated_at"
        ]
      },
      "IdeaCreateRequest": {
        "type": "object",
        "description": "Request body for creating an idea via API key authentication",
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "description": "Title of the idea",
            "example": "Add dark mode support"
          },
          "description": {
            "type": "string",
            "description": "Detailed description of the idea",
            "example": "Users have requested a dark theme for nighttime use"
          },
          "tag_ids": {
            "type": "array",
            "description": "List of tag identifiers to associate with this idea",
            "items": {
              "type": "string"
            },
            "example": [
              "507f1f77bcf86cd799439050"
            ]
          },
          "author_email": {
            "type": "string",
            "description": "Email address of the author (for attribution)",
            "example": "customer@example.com"
          }
        },
        "required": [
          "title"
        ]
      },
      "IdeaUpdate": {
        "type": "object",
        "description": "Fields to update on an idea. At least one field must be provided.",
        "properties": {
          "title": {
            "type": "string",
            "minLength": 1,
            "description": "Updated title",
            "example": "Add dark mode and high contrast support"
          },
          "description": {
            "type": "string",
            "description": "Updated description",
            "example": "Updated description with more details"
          },
          "status": {
            "$ref": "#/components/schemas/IdeaStatus"
          },
          "tag_ids": {
            "type": "array",
            "description": "Updated list of tag identifiers",
            "items": {
              "type": "string"
            }
          },
          "admin_response": {
            "type": "string",
            "description": "Public response from an admin or team member",
            "example": "Great idea! We have this on our roadmap for Q2."
          }
        }
      },
      "IdeaMergeRequest": {
        "type": "object",
        "description": "Target of an idea merge.",
        "required": [
          "target_id"
        ],
        "properties": {
          "target_id": {
            "type": "string",
            "description": "The canonical idea that receives the votes and comments"
          }
        }
      },
      "IdeaMergeResult": {
        "type": "object",
        "description": "Result of merging an idea into another.",
        "required": [
          "source_id",
          "target_id",
          "votes_migrated",
          "votes_deduplicated",
          "comments_migrated"
        ],
        "properties": {
          "source_id": {
            "type": "string",
            "description": "The merged-away idea (now Duplicate)"
          },
          "target_id": {
            "type": "string",
            "description": "The canonical idea"
          },
          "votes_migrated": {
            "type": "integer",
            "description": "Votes moved to the target"
          },
          "votes_deduplicated": {
            "type": "integer",
            "description": "Votes dropped because the voter had already voted for the target"
          },
          "comments_migrated": {
            "type": "integer",
            "description": "Comments re-parented onto the target"
          }
        }
      },
      "IdeaListResponse": {
        "type": "object",
        "description": "Paginated list of ideas",
        "properties": {
          "ideas": {
            "type": "array",
            "description": "Array of idea items",
            "items": {
              "$ref": "#/components/schemas/Idea"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/PaginationInfo"
          }
        },
        "required": [
          "ideas",
          "pagination"
        ]
      },
      "ContactMessageStatus": {
        "type": "string",
        "description": "Status of a contact message",
        "enum": [
          "New",
          "Read",
          "Replied",
          "Archived"
        ]
      },
      "ContactMessage": {
        "type": "object",
        "description": "A contact message submitted via the API",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the contact message",
            "example": "507f1f77bcf86cd799439011"
          },
          "project_id": {
            "type": "string",
            "description": "The project this message belongs to",
            "example": "507f1f77bcf86cd799439022"
          },
          "name": {
            "type": "string",
            "description": "Name of the person who submitted the message",
            "example": "Jane Smith"
          },
          "email": {
            "type": "string",
            "description": "Email address of the sender",
            "example": "jane@example.com"
          },
          "subject": {
            "type": "string",
            "nullable": true,
            "description": "Subject of the message (if provided)",
            "example": "Question about billing"
          },
          "message": {
            "type": "string",
            "description": "The message body",
            "example": "I have a question about my subscription invoice."
          },
          "status": {
            "$ref": "#/components/schemas/ContactMessageStatus"
          },
          "path": {
            "type": "string",
            "nullable": true,
            "description": "URL path where the message was submitted (if available)",
            "example": "/pricing"
          },
          "version": {
            "type": "string",
            "nullable": true,
            "description": "Application version when the message was submitted (if tracked)",
            "example": "1.2.3"
          },
          "archived": {
            "type": "boolean",
            "description": "Whether the message has been archived",
            "example": false
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp when the message was submitted",
            "example": "2024-01-15T10:30:00Z"
          }
        },
        "required": [
          "id",
          "project_id",
          "name",
          "email",
          "message",
          "status",
          "archived",
          "created_at"
        ]
      },
      "ContactMessageStatusUpdate": {
        "type": "object",
        "description": "Request body for updating a contact message status. The status field is required.",
        "properties": {
          "status": {
            "$ref": "#/components/schemas/ContactMessageStatus"
          }
        },
        "required": [
          "status"
        ]
      },
      "ContactMessageListResponse": {
        "type": "object",
        "description": "Paginated list of contact messages",
        "properties": {
          "messages": {
            "type": "array",
            "description": "Array of contact message items",
            "items": {
              "$ref": "#/components/schemas/ContactMessage"
            }
          },
          "pagination": {
            "$ref": "#/components/schemas/PaginationInfo"
          }
        },
        "required": [
          "messages",
          "pagination"
        ]
      },
      "CancellationReason": {
        "type": "string",
        "description": "Reason the customer cancelled their subscription",
        "enum": [
          "CustomerService",
          "LowQuality",
          "MissingFeatures",
          "SwitchedService",
          "TooComplex",
          "TooExpensive",
          "Unused",
          "Other",
          "Unknown"
        ]
      },
      "ChurnProvider": {
        "type": "string",
        "description": "Payment provider that reported the cancellation",
        "enum": [
          "Polar",
          "Stripe"
        ]
      },
      "ChurnEvent": {
        "type": "object",
        "description": "A churn event representing a subscription cancellation from a payment provider",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the churn event",
            "example": "507f1f77bcf86cd799439011"
          },
          "project_id": {
            "type": "string",
            "description": "The project this churn event belongs to",
            "example": "507f1f77bcf86cd799439022"
          },
          "provider": {
            "$ref": "#/components/schemas/ChurnProvider"
          },
          "subscription_id": {
            "type": "string",
            "description": "Subscription identifier from the payment provider",
            "example": "sub_abc123"
          },
          "customer_id": {
            "type": "string",
            "nullable": true,
            "description": "Customer identifier from the payment provider (if available)",
            "example": "cus_xyz"
          },
          "customer_email": {
            "type": "string",
            "nullable": true,
            "description": "Customer email address (if available)",
            "example": "user@example.com"
          },
          "reason": {
            "$ref": "#/components/schemas/CancellationReason"
          },
          "comment": {
            "type": "string",
            "nullable": true,
            "description": "Free-text cancellation comment from the customer (if provided)",
            "example": "Price is too high for my budget"
          },
          "product_name": {
            "type": "string",
            "nullable": true,
            "description": "Name of the cancelled product or plan (if available)",
            "example": "Starter Plan"
          },
          "canceled_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp when the subscription was cancelled",
            "example": "2024-01-15T10:30:00Z"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "description": "ISO 8601 timestamp when the churn event was recorded in SeggWat",
            "example": "2024-01-15T10:30:05Z"
          }
        },
        "required": [
          "id",
          "project_id",
          "provider",
          "subscription_id",
          "reason",
          "canceled_at",
          "created_at"
        ]
      },
      "ChurnStats": {
        "type": "object",
        "description": "Aggregated churn statistics for a project",
        "properties": {
          "total": {
            "type": "integer",
            "description": "Total number of churn events recorded",
            "example": 12
          },
          "this_month": {
            "type": "integer",
            "description": "Number of churn events in the current calendar month",
            "example": 3
          },
          "last_month": {
            "type": "integer",
            "description": "Number of churn events in the previous calendar month",
            "example": 5
          },
          "by_reason": {
            "type": "object",
            "description": "Churn event count grouped by cancellation reason. All reasons are always present (with 0 if none).",
            "additionalProperties": {
              "type": "integer"
            },
            "example": {
              "TooExpensive": 4,
              "MissingFeatures": 3,
              "SwitchedService": 2,
              "Unused": 2,
              "Other": 1,
              "LowQuality": 0,
              "TooComplex": 0,
              "CustomerService": 0,
              "Unknown": 0
            }
          }
        },
        "required": [
          "total",
          "this_month",
          "last_month",
          "by_reason"
        ]
      },
      "SurveyEventKind": {
        "type": "string",
        "description": "Lifecycle event a widget can report. `dispatched` is incremented server-side from the lifecycle dispatcher, `link_clicked` from the magic-link landing handler, and `submitted` from the submit endpoint; those three must not be sent by clients. `shown`, `started`, and `dismissed` are widget-fired.",
        "enum": [
          "dispatched",
          "link_clicked",
          "shown",
          "started",
          "dismissed",
          "submitted"
        ]
      },
      "SurveyEventInput": {
        "type": "object",
        "description": "One event against a specific survey.",
        "properties": {
          "survey_id": {
            "type": "string",
            "description": "MongoDB ObjectId of the survey the event applies to. Events for surveys that do not belong to the request's project are dropped silently."
          },
          "kind": {
            "$ref": "#/components/schemas/SurveyEventKind"
          }
        },
        "required": [
          "survey_id",
          "kind"
        ]
      },
      "SurveyEventsBatch": {
        "type": "object",
        "description": "Batch of survey widget events. Counted server-side as `(project, survey, day_utc, kind)` aggregates — no per-respondent attribution.",
        "properties": {
          "project_key": {
            "type": "string",
            "format": "uuid",
            "description": "Public project key from the widget script tag."
          },
          "events": {
            "type": "array",
            "minItems": 1,
            "maxItems": 32,
            "items": {
              "$ref": "#/components/schemas/SurveyEventInput"
            }
          }
        },
        "required": [
          "project_key",
          "events"
        ]
      },
      "SurveyEventsResponse": {
        "type": "object",
        "description": "Acknowledgement for a tracked event batch.",
        "properties": {
          "accepted": {
            "type": "integer",
            "minimum": 0,
            "description": "Number of events from the batch that passed validation and were counted. May be less than the input length when individual events were dropped (unknown survey id, mismatched project)."
          }
        },
        "required": [
          "accepted"
        ]
      },
      "SurveyStatus": {
        "type": "string",
        "description": "Authoring/lifecycle status of a survey. Only `live` surveys are served by the widget or fired by the lifecycle dispatcher.",
        "enum": [
          "draft",
          "live",
          "paused",
          "archived"
        ]
      },
      "SurveyDisplayMode": {
        "type": "string",
        "description": "Render surface the survey widget uses for this survey.",
        "enum": [
          "banner",
          "modal",
          "inline"
        ],
        "default": "banner"
      },
      "ChoiceOption": {
        "type": "object",
        "description": "One option in a SingleChoice or MultiChoice question.",
        "properties": {
          "id": {
            "type": "string",
            "description": "Stable identifier within the question.",
            "example": "opt_1"
          },
          "label": {
            "type": "string",
            "description": "Visible option label.",
            "example": "Price"
          },
          "allow_other_text": {
            "type": "boolean",
            "description": "When true, selecting this option reveals a free-text input.",
            "default": false
          }
        },
        "required": [
          "id",
          "label"
        ]
      },
      "SurveyQuestion": {
        "type": "object",
        "description": "A single question inside a survey. The `kind` field is a tagged union discriminated by `type`.",
        "properties": {
          "id": {
            "type": "string",
            "description": "Stable identifier unique within the survey. Survives reorders and edits — response rows reference this.",
            "example": "q_nps_1"
          },
          "prompt": {
            "type": "string",
            "description": "The visible question text.",
            "example": "How likely are you to recommend us to a friend?"
          },
          "help_text": {
            "type": "string",
            "nullable": true,
            "description": "Optional helper text shown beneath the prompt."
          },
          "required": {
            "type": "boolean",
            "description": "When true, respondents must answer before submitting.",
            "default": false
          },
          "kind": {
            "$ref": "#/components/schemas/QuestionKind"
          }
        },
        "required": [
          "id",
          "prompt",
          "kind"
        ]
      },
      "QuestionKind": {
        "description": "The input shape of a survey question. Discriminated by `type`.",
        "oneOf": [
          {
            "type": "object",
            "description": "Free-text response.",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "open_text"
                ]
              },
              "max_chars": {
                "type": "integer",
                "nullable": true,
                "description": "Optional character limit."
              },
              "placeholder": {
                "type": "string",
                "nullable": true,
                "description": "Optional placeholder text."
              }
            },
            "required": [
              "type"
            ]
          },
          {
            "type": "object",
            "description": "Numeric scale (CSAT 1-5, CES 1-7, or custom range).",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "scale"
                ]
              },
              "min": {
                "type": "integer",
                "description": "Minimum scale value.",
                "example": 1
              },
              "max": {
                "type": "integer",
                "description": "Maximum scale value.",
                "example": 5
              },
              "low_label": {
                "type": "string",
                "nullable": true,
                "description": "Label for the low end of the scale."
              },
              "high_label": {
                "type": "string",
                "nullable": true,
                "description": "Label for the high end of the scale."
              }
            },
            "required": [
              "type",
              "min",
              "max"
            ]
          },
          {
            "type": "object",
            "description": "Net Promoter Score — 0-10 with detractor/passive/promoter bands.",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "nps"
                ]
              }
            },
            "required": [
              "type"
            ]
          },
          {
            "type": "object",
            "description": "Pick exactly one option.",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "single_choice"
                ]
              },
              "options": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ChoiceOption"
                }
              }
            },
            "required": [
              "type",
              "options"
            ]
          },
          {
            "type": "object",
            "description": "Pick one or more options.",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "multi_choice"
                ]
              },
              "options": {
                "type": "array",
                "items": {
                  "$ref": "#/components/schemas/ChoiceOption"
                }
              },
              "min": {
                "type": "integer",
                "description": "Minimum selections required.",
                "default": 1
              },
              "max": {
                "type": "integer",
                "nullable": true,
                "description": "Maximum selections allowed. Null means unlimited."
              }
            },
            "required": [
              "type",
              "options"
            ]
          },
          {
            "type": "object",
            "description": "Two-way toggle (e.g. Was this useful?).",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "boolean"
                ]
              },
              "true_label": {
                "type": "string",
                "example": "Yes"
              },
              "false_label": {
                "type": "string",
                "example": "No"
              }
            },
            "required": [
              "type",
              "true_label",
              "false_label"
            ]
          }
        ],
        "discriminator": {
          "propertyName": "type"
        }
      },
      "SurveyTrigger": {
        "description": "When and where the survey fires. Discriminated by `source`. Currently only `client_side` is supported.",
        "oneOf": [
          {
            "type": "object",
            "description": "Client-side trigger evaluated by the widget. A *where* gate (`url_patterns`, combined per `url_match`) is AND-combined with a *when* group (events, time, scroll, exit-intent, combined per `when_match`). `exclude_url_patterns` always takes precedence.",
            "properties": {
              "source": {
                "type": "string",
                "enum": [
                  "client_side"
                ]
              },
              "url_patterns": {
                "type": "array",
                "description": "Where gate: glob patterns for URLs where this survey may fire. Empty means any page.",
                "items": {
                  "type": "string"
                },
                "example": [
                  "/pricing/*",
                  "/checkout"
                ]
              },
              "url_match": {
                "type": "string",
                "enum": [
                  "any",
                  "all"
                ],
                "default": "any",
                "description": "How `url_patterns` combine. `any` (default) fires on any matching path; `all` requires every pattern to match."
              },
              "exclude_url_patterns": {
                "type": "array",
                "description": "Glob patterns for URLs where this survey must never fire.",
                "items": {
                  "type": "string"
                },
                "default": []
              },
              "event_names": {
                "type": "array",
                "description": "Custom JS event names that trigger the survey.",
                "items": {
                  "type": "string"
                },
                "default": []
              },
              "show_after_seconds": {
                "type": "integer",
                "nullable": true,
                "description": "Fire after the visitor has been on the page this many seconds (foreground time only)."
              },
              "show_after_scroll_percent": {
                "type": "integer",
                "nullable": true,
                "minimum": 1,
                "maximum": 100,
                "description": "Fire once the visitor has scrolled this percentage of the page."
              },
              "show_on_exit_intent": {
                "type": "boolean",
                "description": "Fire when the pointer leaves the viewport toward the browser chrome (exit-intent). Desktop only.",
                "default": false
              },
              "when_match": {
                "type": "string",
                "enum": [
                  "any",
                  "all"
                ],
                "default": "any",
                "description": "How the *when* conditions (events, time, scroll, exit-intent) combine. `any` (default) fires on the first met; `all` requires every condition to be met."
              }
            },
            "required": [
              "source"
            ]
          }
        ],
        "discriminator": {
          "propertyName": "source"
        }
      },
      "ShowTo": {
        "type": "string",
        "description": "Who the thank-you action is shown to.",
        "enum": [
          "completers",
          "all_respondents"
        ],
        "default": "completers"
      },
      "ThankYouAction": {
        "description": "What the respondent sees after submitting. Discriminated by `type`.",
        "oneOf": [
          {
            "type": "object",
            "description": "Plain text confirmation.",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "message"
                ]
              },
              "headline": {
                "type": "string",
                "example": "Thank you for your feedback!"
              },
              "body": {
                "type": "string",
                "nullable": true,
                "description": "Optional longer text shown beneath the headline."
              }
            },
            "required": [
              "type",
              "headline"
            ]
          },
          {
            "type": "object",
            "description": "Reward completers with a coupon code.",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "discount_offer"
                ]
              },
              "headline": {
                "type": "string",
                "example": "Thanks — here's 30% off your first 3 months."
              },
              "coupon_code": {
                "type": "string",
                "description": "Customer-managed coupon code matched against Polar/Stripe.",
                "example": "COMEBACK30"
              },
              "cta_label": {
                "type": "string",
                "example": "Claim discount"
              },
              "cta_url": {
                "type": "string",
                "format": "uri",
                "description": "URL the CTA button points to, typically the checkout page with the coupon prefilled.",
                "example": "https://example.com/upgrade?coupon=COMEBACK30"
              },
              "show_to": {
                "$ref": "#/components/schemas/ShowTo"
              }
            },
            "required": [
              "type",
              "headline",
              "coupon_code",
              "cta_label",
              "cta_url"
            ]
          },
          {
            "type": "object",
            "description": "Encourage churned or lapsed users to reactivate.",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "reactivate"
                ]
              },
              "headline": {
                "type": "string",
                "example": "We'd love to have you back."
              },
              "cta_label": {
                "type": "string",
                "example": "Reactivate"
              },
              "cta_url": {
                "type": "string",
                "format": "uri"
              }
            },
            "required": [
              "type",
              "headline",
              "cta_label",
              "cta_url"
            ]
          },
          {
            "type": "object",
            "description": "Arbitrary HTML rendered in the thank-you slot.",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "custom"
                ]
              },
              "html": {
                "type": "string",
                "description": "Raw HTML string."
              }
            },
            "required": [
              "type",
              "html"
            ]
          }
        ],
        "discriminator": {
          "propertyName": "type"
        }
      },
      "SurveyCopyLocale": {
        "type": "object",
        "description": "Copy overrides for a single locale.",
        "properties": {
          "title": {
            "type": "string",
            "nullable": true,
            "description": "Survey-level title override."
          },
          "intro": {
            "type": "string",
            "nullable": true,
            "description": "Survey-level intro shown beneath the title."
          },
          "question_prompts": {
            "type": "object",
            "description": "Per-question prompt overrides, keyed by question id.",
            "additionalProperties": {
              "type": "string"
            }
          },
          "submit_label": {
            "type": "string",
            "nullable": true,
            "description": "Submit button label override."
          }
        }
      },
      "SurveyCopyConfig": {
        "type": "object",
        "description": "Per-locale copy overrides. Absent locales fall back to the prompt text on each question.",
        "properties": {
          "locales": {
            "type": "object",
            "description": "Map of BCP 47 locale tag to overrides.",
            "additionalProperties": {
              "$ref": "#/components/schemas/SurveyCopyLocale"
            },
            "example": {
              "de": {
                "title": "Wie zufrieden sind Sie?",
                "submit_label": "Absenden"
              }
            }
          }
        }
      },
      "Survey": {
        "type": "object",
        "description": "A survey definition. Persisted once per project; rendered to many respondents.",
        "properties": {
          "id": {
            "type": "string",
            "description": "MongoDB ObjectId hex string.",
            "example": "6630f1c7c2b3a40a1e9e1b22"
          },
          "project_id": {
            "type": "string",
            "description": "The project this survey belongs to.",
            "example": "507f1f77bcf86cd799439011"
          },
          "name": {
            "type": "string",
            "description": "Human-readable survey name shown in the dashboard.",
            "example": "Pricing page intent"
          },
          "status": {
            "$ref": "#/components/schemas/SurveyStatus"
          },
          "questions": {
            "type": "array",
            "description": "Ordered question list. Order is the display order.",
            "items": {
              "$ref": "#/components/schemas/SurveyQuestion"
            }
          },
          "trigger": {
            "$ref": "#/components/schemas/SurveyTrigger"
          },
          "thank_you": {
            "$ref": "#/components/schemas/ThankYouAction"
          },
          "cooldown_days": {
            "type": "integer",
            "description": "Days to wait before re-prompting the same user.",
            "default": 90,
            "example": 90
          },
          "sample_rate": {
            "type": "number",
            "format": "float",
            "description": "Fraction of eligible visits actually prompted (0.0–1.0). 1.0 means everyone qualifies.",
            "default": 1.0,
            "minimum": 0.0,
            "maximum": 1.0,
            "example": 1.0
          },
          "copy": {
            "$ref": "#/components/schemas/SurveyCopyConfig"
          },
          "display_mode": {
            "$ref": "#/components/schemas/SurveyDisplayMode"
          },
          "created_at": {
            "type": "string",
            "format": "date-time",
            "example": "2024-01-15T10:30:00Z"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time",
            "example": "2024-01-20T14:00:00Z"
          }
        },
        "required": [
          "id",
          "project_id",
          "name",
          "status",
          "questions",
          "trigger",
          "thank_you",
          "cooldown_days",
          "sample_rate",
          "copy",
          "display_mode",
          "created_at",
          "updated_at"
        ]
      },
      "SurveyListItem": {
        "type": "object",
        "description": "Survey plus denormalized response count. Returned by the list endpoint.",
        "properties": {
          "survey": {
            "$ref": "#/components/schemas/Survey"
          },
          "response_count": {
            "type": "integer",
            "description": "Total number of response rows for this survey.",
            "example": 42
          }
        },
        "required": [
          "survey",
          "response_count"
        ]
      },
      "CreateSurveyRequest": {
        "type": "object",
        "description": "Request body for creating a survey from a canonical template.",
        "properties": {
          "template": {
            "type": "string",
            "description": "Which canonical template to instantiate. `trial_exit` is intentionally excluded — that template requires billing context and is managed via the dashboard.",
            "enum": [
              "blank",
              "nps",
              "csat",
              "ces"
            ],
            "example": "nps"
          }
        },
        "required": [
          "template"
        ]
      },
      "SetSurveyStatusRequest": {
        "type": "object",
        "description": "Request body for updating a survey's lifecycle status.",
        "properties": {
          "status": {
            "$ref": "#/components/schemas/SurveyStatus"
          }
        },
        "required": [
          "status"
        ]
      },
      "ResponseTimelinePoint": {
        "type": "object",
        "description": "Daily response count for the survey timeline.",
        "properties": {
          "date": {
            "type": "string",
            "description": "UTC date in YYYY-MM-DD format.",
            "example": "2024-01-15"
          },
          "count": {
            "type": "integer",
            "description": "Number of responses on this day.",
            "example": 12
          }
        },
        "required": [
          "date",
          "count"
        ]
      },
      "QuestionStats": {
        "description": "Per-question aggregation. Discriminated by `kind`, matching the question's type.",
        "oneOf": [
          {
            "type": "object",
            "description": "NPS distribution + computed score.",
            "properties": {
              "kind": {
                "type": "string",
                "enum": [
                  "nps"
                ]
              },
              "answered": {
                "type": "integer",
                "example": 200
              },
              "score": {
                "type": "integer",
                "description": "NPS score (-100 to 100).",
                "example": 45
              },
              "promoters": {
                "type": "integer",
                "example": 120
              },
              "passives": {
                "type": "integer",
                "example": 50
              },
              "detractors": {
                "type": "integer",
                "example": 30
              },
              "distribution": {
                "type": "object",
                "description": "Count by score. Keys are stringified integers \"0\"–\"10\".",
                "additionalProperties": {
                  "type": "integer"
                }
              }
            },
            "required": [
              "kind",
              "answered",
              "score",
              "promoters",
              "passives",
              "detractors",
              "distribution"
            ]
          },
          {
            "type": "object",
            "description": "Arbitrary numeric scale statistics.",
            "properties": {
              "kind": {
                "type": "string",
                "enum": [
                  "scale"
                ]
              },
              "answered": {
                "type": "integer",
                "example": 85
              },
              "min": {
                "type": "integer",
                "example": 1
              },
              "max": {
                "type": "integer",
                "example": 5
              },
              "average": {
                "type": "number",
                "format": "double",
                "example": 4.2
              },
              "distribution": {
                "type": "object",
                "description": "Count by integer value. Keys are stringified integers.",
                "additionalProperties": {
                  "type": "integer"
                }
              }
            },
            "required": [
              "kind",
              "answered",
              "min",
              "max",
              "average",
              "distribution"
            ]
          },
          {
            "type": "object",
            "description": "Single- or multi-choice option counts.",
            "properties": {
              "kind": {
                "type": "string",
                "enum": [
                  "choice"
                ]
              },
              "answered": {
                "type": "integer",
                "example": 60
              },
              "per_option": {
                "type": "object",
                "description": "Per-option counts keyed by ChoiceOption.id.",
                "additionalProperties": {
                  "type": "integer"
                }
              },
              "other_text_samples": {
                "type": "array",
                "description": "Recent \"other:\" free-text companions, newest first (max 50).",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "kind",
              "answered",
              "per_option",
              "other_text_samples"
            ]
          },
          {
            "type": "object",
            "description": "Two-way toggle counts.",
            "properties": {
              "kind": {
                "type": "string",
                "enum": [
                  "boolean"
                ]
              },
              "answered": {
                "type": "integer",
                "example": 30
              },
              "true_count": {
                "type": "integer",
                "example": 22
              },
              "false_count": {
                "type": "integer",
                "example": 8
              }
            },
            "required": [
              "kind",
              "answered",
              "true_count",
              "false_count"
            ]
          },
          {
            "type": "object",
            "description": "Open-text answers with recent samples.",
            "properties": {
              "kind": {
                "type": "string",
                "enum": [
                  "text"
                ]
              },
              "answered": {
                "type": "integer",
                "example": 15
              },
              "recent_samples": {
                "type": "array",
                "description": "Recent text answers, newest first (max 50).",
                "items": {
                  "type": "string"
                }
              }
            },
            "required": [
              "kind",
              "answered",
              "recent_samples"
            ]
          },
          {
            "type": "object",
            "description": "Question has zero non-skipped answers.",
            "properties": {
              "kind": {
                "type": "string",
                "enum": [
                  "empty"
                ]
              }
            },
            "required": [
              "kind"
            ]
          }
        ],
        "discriminator": {
          "propertyName": "kind"
        }
      },
      "QuestionStatsEntry": {
        "type": "object",
        "description": "Per-question stats entry in SurveyResponseStats.",
        "properties": {
          "question_id": {
            "type": "string",
            "description": "Stable question identifier.",
            "example": "q_nps_1"
          },
          "prompt": {
            "type": "string",
            "description": "Prompt text to display. Falls back to the response snapshot when the question is no longer in the definition.",
            "example": "How likely are you to recommend us?"
          },
          "is_archived": {
            "type": "boolean",
            "description": "True when this question_id is no longer in the current survey definition but historical responses still reference it.",
            "example": false
          },
          "stats": {
            "$ref": "#/components/schemas/QuestionStats"
          }
        },
        "required": [
          "question_id",
          "prompt",
          "is_archived",
          "stats"
        ]
      },
      "SurveyResponseStats": {
        "type": "object",
        "description": "Aggregated analytics for a single survey.",
        "properties": {
          "survey_id": {
            "type": "string",
            "description": "MongoDB ObjectId of the survey.",
            "example": "6630f1c7c2b3a40a1e9e1b22"
          },
          "total_responses": {
            "type": "integer",
            "description": "Total response rows, including incomplete submissions.",
            "example": 250
          },
          "completed_responses": {
            "type": "integer",
            "description": "Subset of total_responses where every required question was answered.",
            "example": 200
          },
          "questions": {
            "type": "array",
            "description": "Per-question stats in survey display order. Archived questions are appended at the end.",
            "items": {
              "$ref": "#/components/schemas/QuestionStatsEntry"
            }
          },
          "timeline": {
            "type": "array",
            "description": "Daily response counts (UTC), oldest to newest. Empty when there are no responses.",
            "items": {
              "$ref": "#/components/schemas/ResponseTimelinePoint"
            }
          }
        },
        "required": [
          "survey_id",
          "total_responses",
          "completed_responses",
          "questions",
          "timeline"
        ]
      },
      "ChangelogStatus": {
        "type": "string",
        "enum": [
          "draft",
          "published",
          "hidden"
        ],
        "description": "Lifecycle status. Only `published` entries appear on the public board; `hidden` soft-hides without deleting."
      },
      "ChangelogCategory": {
        "type": "string",
        "enum": [
          "added",
          "improved",
          "fixed",
          "changed",
          "removed",
          "security"
        ],
        "description": "Optional \"Keep a Changelog\"-style category, used for grouping and the public page's filter pills."
      },
      "ChangelogSource": {
        "type": "string",
        "enum": [
          "manual",
          "github_release",
          "completed_idea"
        ],
        "description": "Where the entry originated. Synced sources are deduplicated by `source_ref` and never overwrite an entry once ingested."
      },
      "ChangelogEntry": {
        "type": "object",
        "description": "One entry on a project's public changelog stream.",
        "properties": {
          "id": {
            "type": "string",
            "example": "6630f1c7c2b3a40a1e9e1b33"
          },
          "project_id": {
            "type": "string",
            "example": "6630f1c7c2b3a40a1e9e1b11"
          },
          "title": {
            "type": "string",
            "example": "Dark mode"
          },
          "body": {
            "type": "string",
            "description": "Markdown body, rendered (sanitized) on the public board.",
            "example": "The dashboard and widgets now follow your OS theme."
          },
          "version": {
            "type": "string",
            "nullable": true,
            "description": "Optional version badge. Entries sharing a (component, version) pair render as one release block on the public page.",
            "example": "v1.4.0"
          },
          "category": {
            "allOf": [
              {
                "$ref": "#/components/schemas/ChangelogCategory"
              }
            ],
            "nullable": true
          },
          "component": {
            "type": "string",
            "nullable": true,
            "description": "Slug of the product component (CLI, Dashboard, React SDK, …) from the project's component registry. Keeps `version` a pure version for multi-asset changelogs.",
            "example": "react-sdk"
          },
          "source": {
            "$ref": "#/components/schemas/ChangelogSource"
          },
          "source_ref": {
            "type": "string",
            "nullable": true,
            "description": "Stable per-source id used for sync dedupe (GitHub release id, idea id). `null` for manual entries."
          },
          "status": {
            "$ref": "#/components/schemas/ChangelogStatus"
          },
          "published_at": {
            "type": "string",
            "format": "date-time",
            "nullable": true,
            "description": "Display date and public ordering key. Stamped on first publish when not set explicitly."
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        },
        "required": [
          "id",
          "project_id",
          "title",
          "body",
          "source",
          "status",
          "created_at",
          "updated_at"
        ]
      },
      "ChangelogCreateRequest": {
        "type": "object",
        "description": "A new hand-authored entry (`source = manual`).",
        "properties": {
          "title": {
            "type": "string",
            "example": "Dark mode"
          },
          "body": {
            "type": "string",
            "description": "Markdown body.",
            "default": ""
          },
          "version": {
            "type": "string",
            "nullable": true,
            "example": "v1.4.0"
          },
          "category": {
            "allOf": [
              {
                "$ref": "#/components/schemas/ChangelogCategory"
              }
            ],
            "nullable": true
          },
          "component": {
            "type": "string",
            "nullable": true,
            "description": "Component slug from the project's registry. Unknown slugs are rejected with a 400 listing the valid ones.",
            "example": "cli"
          },
          "publish": {
            "type": "boolean",
            "default": false,
            "description": "Publish to the public board immediately instead of landing as a draft."
          },
          "published_at": {
            "type": "string",
            "nullable": true,
            "description": "Explicit display date (RFC 3339 or `YYYY-MM-DD`) for importing existing changelog history. Defaults to the publish moment.",
            "example": "2025-11-03"
          }
        },
        "required": [
          "title"
        ]
      },
      "ChangelogUpdateRequest": {
        "type": "object",
        "description": "Replacement content for an entry. Full-document semantics: omitted `version`/`category`/`component` are cleared.",
        "properties": {
          "title": {
            "type": "string"
          },
          "body": {
            "type": "string",
            "description": "Markdown body.",
            "default": ""
          },
          "version": {
            "type": "string",
            "nullable": true
          },
          "category": {
            "allOf": [
              {
                "$ref": "#/components/schemas/ChangelogCategory"
              }
            ],
            "nullable": true
          },
          "component": {
            "type": "string",
            "nullable": true,
            "description": "Component slug from the project's registry. Unknown slugs are rejected with a 400 listing the valid ones."
          }
        },
        "required": [
          "title"
        ]
      },
      "SetChangelogStatusRequest": {
        "type": "object",
        "properties": {
          "status": {
            "$ref": "#/components/schemas/ChangelogStatus"
          }
        },
        "required": [
          "status"
        ]
      },
      "AgentCategory": {
        "type": "string",
        "enum": [
          "bug",
          "docs_mismatch",
          "friction",
          "feature_gap",
          "quality_degradation",
          "other"
        ]
      },
      "AgentSeverity": {
        "type": "string",
        "enum": [
          "critical",
          "high",
          "medium",
          "low"
        ]
      },
      "AgentReproducibility": {
        "type": "string",
        "enum": [
          "always",
          "sometimes",
          "intermittent",
          "once"
        ]
      },
      "AgentSurfaceKind": {
        "type": "string",
        "enum": [
          "api_endpoint",
          "docs_page",
          "cli_command",
          "sdk_method",
          "other"
        ]
      },
      "AgentEvidenceType": {
        "type": "string",
        "enum": [
          "http_summary",
          "stderr_excerpt",
          "repro_steps",
          "screenshot",
          "log_excerpt",
          "other"
        ]
      },
      "AgentFeedbackInput": {
        "type": "object",
        "required": [
          "subject",
          "signal",
          "content"
        ],
        "properties": {
          "reporter": {
            "type": "object",
            "properties": {
              "agent_vendor": {
                "type": "string"
              },
              "agent_product": {
                "type": "string"
              },
              "agent_version": {
                "type": "string"
              }
            },
            "description": "Optional. Fields left out are derived from the User-Agent header's first name/version token; agent_vendor defaults to \"unknown\"."
          },
          "subject": {
            "type": "object",
            "required": [
              "surface"
            ],
            "properties": {
              "surface": {
                "type": "string",
                "description": "Endpoint path, docs URL, CLI command or SDK method the agent was using."
              },
              "domain": {
                "type": "string",
                "description": "Defaults to the host of the project's first allowed origin, or \"unknown\"."
              },
              "kind": {
                "$ref": "#/components/schemas/AgentSurfaceKind"
              },
              "product": {
                "type": "string"
              }
            }
          },
          "signal": {
            "type": "object",
            "required": [
              "category"
            ],
            "properties": {
              "category": {
                "$ref": "#/components/schemas/AgentCategory"
              },
              "severity": {
                "allOf": [
                  {
                    "$ref": "#/components/schemas/AgentSeverity"
                  }
                ],
                "default": "medium",
                "description": "Defaults to medium."
              },
              "confidence": {
                "type": "number",
                "minimum": 0,
                "maximum": 1,
                "default": 0.5,
                "description": "Defaults to 0.5."
              },
              "reproducibility": {
                "$ref": "#/components/schemas/AgentReproducibility"
              }
            }
          },
          "content": {
            "type": "object",
            "required": [
              "title"
            ],
            "properties": {
              "title": {
                "type": "string",
                "maxLength": 256
              },
              "summary": {
                "type": "string",
                "maxLength": 4096
              },
              "hypothesis": {
                "type": "string",
                "maxLength": 2048
              }
            }
          },
          "evidence": {
            "type": "array",
            "maxItems": 10,
            "items": {
              "type": "object",
              "required": [
                "type",
                "content"
              ],
              "properties": {
                "type": {
                  "$ref": "#/components/schemas/AgentEvidenceType"
                },
                "content": {
                  "type": "string",
                  "description": "Up to 65536 bytes."
                },
                "redacted": {
                  "type": "boolean",
                  "default": false
                }
              }
            }
          }
        }
      },
      "AgentReceipt": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "feedback_id": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "accepted"
            ]
          },
          "evidence_ids": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "AgentReceiptResponse": {
        "type": "object",
        "properties": {
          "receipt": {
            "$ref": "#/components/schemas/AgentReceipt"
          }
        }
      },
      "AgentReceiptLookup": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "feedback_id": {
                "type": "string"
              },
              "observation_id": {
                "type": "string",
                "nullable": true
              },
              "status": {
                "type": "string",
                "enum": [
                  "accepted",
                  "rejected"
                ]
              },
              "quality_score": {
                "type": "number",
                "nullable": true
              },
              "duplicate_of": {
                "type": "string",
                "nullable": true
              },
              "created_at": {
                "type": "string",
                "format": "date-time"
              }
            }
          }
        }
      },
      "AgentDiscovery": {
        "type": "object",
        "properties": {
          "schema_version": {
            "type": "string",
            "example": "1.1"
          },
          "name": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "spec_url": {
            "type": "string",
            "format": "uri"
          },
          "policy_url": {
            "type": "string",
            "format": "uri"
          },
          "endpoints": {
            "type": "object",
            "description": "`feedback.submit`, `receipts.get` and `policy.get`, each with `method`, absolute `url` and `description`."
          },
          "categories": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AgentCategory"
            }
          },
          "evidence_types": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AgentEvidenceType"
            }
          },
          "contact": {
            "type": "string",
            "format": "uri"
          }
        }
      },
      "AgentPolicy": {
        "type": "object",
        "properties": {
          "version": {
            "type": "string",
            "example": "1.0"
          },
          "categories": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AgentCategory"
            }
          },
          "severity_levels": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AgentSeverity"
            }
          },
          "reproducibility_options": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AgentReproducibility"
            }
          },
          "evidence_types": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AgentEvidenceType"
            }
          },
          "surface_kinds": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/AgentSurfaceKind"
            }
          },
          "limits": {
            "type": "object",
            "properties": {
              "max_evidence_per_feedback": {
                "type": "integer",
                "example": 10
              },
              "max_evidence_content_bytes": {
                "type": "integer",
                "example": 65536
              },
              "max_title_length": {
                "type": "integer",
                "example": 256
              },
              "max_summary_length": {
                "type": "integer",
                "example": 4096
              },
              "max_hypothesis_length": {
                "type": "integer",
                "example": 2048
              },
              "confidence_range": {
                "type": "object",
                "properties": {
                  "min": {
                    "type": "number"
                  },
                  "max": {
                    "type": "number"
                  }
                }
              }
            }
          },
          "rate_limit_per_hour": {
            "type": "integer",
            "example": 60
          },
          "endpoints": {
            "type": "object",
            "properties": {
              "submit_feedback": {
                "type": "string",
                "format": "uri"
              },
              "get_receipt": {
                "type": "string",
                "format": "uri"
              },
              "discovery": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      },
      "AgentError": {
        "type": "object",
        "required": [
          "error",
          "message"
        ],
        "properties": {
          "error": {
            "type": "string"
          },
          "message": {
            "type": "string"
          }
        }
      },
      "AgentValidationError": {
        "type": "object",
        "required": [
          "error",
          "errors"
        ],
        "properties": {
          "error": {
            "type": "string",
            "enum": [
              "validation_failed"
            ]
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "field": {
                  "type": "string"
                },
                "error": {
                  "type": "string",
                  "enum": [
                    "required",
                    "out_of_range",
                    "too_long",
                    "too_many",
                    "invalid_value",
                    "invalid_json"
                  ]
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "CreateProjectRequest": {
        "type": "object",
        "required": [
          "name"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "Project name; the idempotency key within the organization."
          },
          "description": {
            "type": "string",
            "nullable": true
          },
          "allowed_origins": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "nullable": true,
            "description": "Origins allowed to load the widget. Omitted = `*`."
          },
          "org_id": {
            "type": "string",
            "nullable": true,
            "description": "Organization to create it in. Omitted = the caller's organization."
          }
        }
      },
      "CreateProjectResponse": {
        "type": "object",
        "required": [
          "id",
          "key",
          "name",
          "org_id",
          "allowed_origins",
          "created"
        ],
        "properties": {
          "id": {
            "type": "string"
          },
          "key": {
            "type": "string",
            "description": "Public key the widget embeds as `data-project-key`."
          },
          "name": {
            "type": "string"
          },
          "org_id": {
            "type": "string"
          },
          "allowed_origins": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "created": {
            "type": "boolean",
            "description": "`false` when an existing project was returned."
          }
        }
      },
      "WidgetInstallStatus": {
        "type": "object",
        "properties": {
          "feedback_first_seen": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "helpful_first_seen": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "star_first_seen": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          },
          "share_first_seen": {
            "type": "string",
            "format": "date-time",
            "nullable": true
          }
        }
      },
      "InboxKind": {
        "type": "string",
        "enum": [
          "chat",
          "feedback_thread",
          "feedback",
          "contact",
          "idea",
          "idea_comments"
        ],
        "description": "What an inbox item is, and what `id` refers to: a conversation for `chat`/`feedback_thread`, an idea for `idea`/`idea_comments`, else the feedback or contact message itself."
      },
      "InboxItem": {
        "type": "object",
        "required": [
          "kind",
          "id",
          "snippet",
          "at",
          "needs_reply"
        ],
        "properties": {
          "kind": {
            "$ref": "#/components/schemas/InboxKind"
          },
          "id": {
            "type": "string",
            "example": "507f1f77bcf86cd799439011"
          },
          "person": {
            "type": "string",
            "nullable": true,
            "description": "Display name or email of the end user, when known",
            "example": "mia@example.com"
          },
          "snippet": {
            "type": "string",
            "description": "Latest message, feedback text, idea title or contact subject, capped at 140 characters",
            "example": "How do I export all my feedback as CSV?"
          },
          "at": {
            "type": "string",
            "format": "date-time",
            "description": "Last activity: the latest message for a conversation, else creation time"
          },
          "needs_reply": {
            "type": "boolean",
            "description": "The end user is waiting on the team: they spoke last, or nobody has answered yet"
          },
          "unread": {
            "type": "boolean",
            "description": "Set in the dashboard for items the signed-in member hasn't opened since new activity. Always false over the API"
          }
        }
      },
      "InboxPage": {
        "type": "object",
        "required": [
          "items",
          "has_more"
        ],
        "properties": {
          "items": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/InboxItem"
            }
          },
          "has_more": {
            "type": "boolean"
          }
        }
      },
      "InboxCounts": {
        "type": "object",
        "required": [
          "chat",
          "feedback",
          "contact",
          "ideas"
        ],
        "description": "Open items waiting on the team, grouped like the `filter` parameter (`feedback` covers feedback threads and untriaged feedback; `ideas` covers ideas awaiting approval and new idea comments).",
        "properties": {
          "chat": {
            "type": "integer",
            "minimum": 0
          },
          "feedback": {
            "type": "integer",
            "minimum": 0
          },
          "contact": {
            "type": "integer",
            "minimum": 0
          },
          "ideas": {
            "type": "integer",
            "minimum": 0
          }
        }
      }
    },
    "parameters": {
      "RefererHeader": {
        "name": "Referer",
        "in": "header",
        "required": false,
        "description": "Optional HTTP Referer header indicating the page URL where the submission originated",
        "schema": {
          "type": "string",
          "format": "uri-reference"
        },
        "example": "https://example.com/dashboard"
      },
      "ProjectIdPath": {
        "name": "project_id",
        "in": "path",
        "required": true,
        "description": "Unique identifier of the project (MongoDB ObjectId)",
        "schema": {
          "type": "string"
        },
        "example": "507f1f77bcf86cd799439011"
      }
    },
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "Organization Access Token (OAT). Generate from Settings > API Tokens in the dashboard."
      }
    }
  },
  "tags": [
    {
      "name": "Health",
      "description": "Health check endpoints for monitoring service status"
    },
    {
      "name": "Projects",
      "description": "Endpoints for managing projects"
    },
    {
      "name": "Feedback",
      "description": "Endpoints for submitting and managing user feedback"
    },
    {
      "name": "Ratings",
      "description": "Endpoints for submitting and managing page ratings. Supports multiple rating types: helpful (thumbs up/down), star (1-5 or custom scale), and NPS (Net Promoter Score 0-10)."
    },
    {
      "name": "Surveys",
      "description": "Endpoints for managing surveys — create from a template, publish, pause, archive, and retrieve per-question analytics. The widget-facing submit and event-tracking endpoints are also grouped here."
    },
    {
      "name": "Ideas",
      "description": "Endpoints for managing ideas and user requests."
    },
    {
      "name": "Messages",
      "description": "Endpoints for managing contact messages submitted via the API."
    },
    {
      "name": "Churn",
      "description": "Endpoints for querying subscription cancellation events recorded via Polar and Stripe webhook integrations."
    },
    {
      "name": "Lifecycle",
      "description": "Endpoints for firing lifecycle events and registering customer-user trial state. Powers time-based surveys (trial-ending-soon) and right-now surveys (trial-expired, subscription-cancelled, custom)."
    },
    {
      "name": "Changelog",
      "description": "Curate the public-board changelog. Entries arrive as drafts from three sources (manual authoring, GitHub release sync, completed roadmap ideas) and go live on `/p/{project_key}/changelog` only once published. Published entries are also served as an Atom feed at `/p/{project_key}/changelog/feed.xml` and have per-entry permalink pages."
    },
    {
      "name": "Agent Feedback",
      "description": "Unauthenticated endpoints for autonomous AI agents to file structured reports about a project's API, docs, CLI or SDK. Off by default per project; enable under Project Settings. See the Agent Feedback Reports guide."
    },
    {
      "name": "Inbox",
      "description": "One list of everything waiting on the team in a project: live chats, feedback threads, untriaged feedback, contact messages, ideas awaiting approval and new idea comments. The same rows as the dashboard Inbox, items waiting on you first."
    }
  ]
}
