function isTodoStatus(value) {
    return value === "not-started" || value === "in-progress" || value === "completed";
}
function normalizeTodoToolName(toolName) {
    const normalized = toolName?.trim().toLowerCase() ?? "";
    if (!normalized)
        return "";
    if (normalized === "todo" || normalized === "todowrite")
        return "todo";
    if (normalized.endsWith("__todo"))
        return "todo";
    if (normalized.endsWith("manage_todo_list"))
        return "todo";
    return normalized;
}
function normalizeTodoItems(items) {
    if (!Array.isArray(items))
        return null;
    const normalized = [];
    for (const item of items) {
        if (!item || typeof item !== "object")
            return null;
        const record = item;
        if (typeof record.id !== "number")
            return null;
        if (typeof record.title !== "string")
            return null;
        if (!isTodoStatus(record.status))
            return null;
        normalized.push({
            id: record.id,
            title: record.title,
            status: record.status,
        });
    }
    return normalized;
}
export function extractTodoResultItems(toolName, data, args) {
    const normalizedToolName = normalizeTodoToolName(toolName);
    if (data && typeof data === "object" && "items" in data) {
        const items = normalizeTodoItems(data.items);
        if (items)
            return items;
    }
    if (normalizedToolName === "todo" && args && typeof args === "object" && "todoList" in args) {
        return normalizeTodoItems(args.todoList);
    }
    if (normalizedToolName === "todo" && args && typeof args === "object" && "todos" in args) {
        const rawTodos = args.todos;
        if (!Array.isArray(rawTodos))
            return null;
        const mapped = rawTodos.map((item, index) => {
            const record = item && typeof item === "object" ? item : {};
            const rawStatus = String(record.status ?? "pending");
            const status = rawStatus === "completed" ? "completed"
                : rawStatus === "in_progress" || rawStatus === "in-progress" ? "in-progress"
                    : "not-started";
            return {
                id: typeof record.id === "number" ? record.id : index,
                title: String(record.content ?? record.title ?? ""),
                status,
            };
        });
        return normalizeTodoItems(mapped);
    }
    return null;
}
//# sourceMappingURL=todo-result.js.map