/**
 * Pure REST handlers for `/api/sessions/:sessionId/queue/*`.
 *
 * Same contract as sessions/projects handlers — pure functions that take
 * `store` + `manager` dependencies, throw `BadRequestError`/`NotFoundError`
 * on invalid input, and return typed responses.
 *
 * After mutating the queue, each handler calls `manager.pushQueueState()`
 * to broadcast the updated queue to all subscribers via `queue_changed`.
 */
import { BadRequestError, NotFoundError } from "./errors.js";
export function handleEnqueuePrompt(store, manager, sessionId, body) {
    if (typeof body.content !== "string" || !body.content.trim()) {
        throw new BadRequestError("content (non-empty string) is required");
    }
    const session = store.getSession(sessionId);
    if (!session)
        throw new NotFoundError("Session not found");
    const row = store.enqueuePrompt(sessionId, body.content);
    manager.pushQueueState(sessionId);
    return {
        id: row.id,
        content: row.content,
        position: row.position,
        createdAt: row.created_at,
    };
}
export function handleGetPromptQueue(store, sessionId) {
    const session = store.getSession(sessionId);
    if (!session)
        throw new NotFoundError("Session not found");
    return store.getPromptQueue(sessionId).map((r) => ({
        id: r.id,
        content: r.content,
        position: r.position,
        createdAt: r.created_at,
    }));
}
export function handleRemovePrompt(store, manager, sessionId, itemId) {
    const session = store.getSession(sessionId);
    if (!session)
        throw new NotFoundError("Session not found");
    store.removePrompt(sessionId, itemId);
    manager.pushQueueState(sessionId);
}
export function handleClearPromptQueue(store, manager, sessionId) {
    const session = store.getSession(sessionId);
    if (!session)
        throw new NotFoundError("Session not found");
    store.clearPromptQueue(sessionId);
    manager.pushQueueState(sessionId);
}
