/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { BaseTool, Kind } from './tools.js';
import { TodoStore } from './todo-store.js';
import { Type } from '@google/genai';
import { TodoReminderService } from '../services/todo-reminder-service.js';
import { formatTodoListForDisplay } from '../todo/todoFormatter.js';
import { ToolCallTrackerService } from '../services/tool-call-tracker-service.js';
export class TodoRead extends BaseTool {
    static Name = 'todo_read';
    reminderService = new TodoReminderService();
    constructor() {
        super(TodoRead.Name, 'TodoRead', 'Read the current todo list for the session. Returns all todos with their status, priority, and content.', Kind.Think, {
            type: Type.OBJECT,
            properties: {},
        }, true, // isOutputMarkdown
        false);
    }
    getDescription(_params) {
        return 'Read current todo list';
    }
    async execute(_params, _signal, _updateOutput) {
        // Get session and agent IDs from context
        const sessionId = this.context?.sessionId || 'default';
        const agentId = this.context?.agentId;
        const store = new TodoStore(sessionId, agentId);
        const todos = await store.readTodos();
        const output = formatTodoListForDisplay(todos, {
            getLiveToolCalls: (todoId) => ToolCallTrackerService.getAllToolCalls(sessionId, todoId, agentId),
        });
        if (todos.length === 0) {
            const isComplexTask = false;
            const reminder = this.reminderService.getReminderForEmptyTodos(isComplexTask);
            return {
                llmContent: output + (reminder || ''),
                returnDisplay: output,
            };
        }
        // Calculate metadata
        const statistics = this.calculateStatistics(todos);
        const suggestedAction = this.determineSuggestedAction(todos);
        return {
            llmContent: output,
            returnDisplay: output,
            metadata: {
                totalTasks: todos.length,
                statistics,
                suggestedAction,
            },
        };
    }
    calculateStatistics(todos) {
        return {
            total: todos.length,
            inProgress: todos.filter((t) => t.status === 'in_progress').length,
            pending: todos.filter((t) => t.status === 'pending').length,
            completed: todos.filter((t) => t.status === 'completed').length,
            highPriority: todos.filter((t) => t.priority === 'high').length,
            mediumPriority: todos.filter((t) => t.priority === 'medium').length,
            lowPriority: todos.filter((t) => t.priority === 'low').length,
        };
    }
    determineSuggestedAction(todos) {
        // Check if any tasks are in progress
        const inProgressTasks = todos.filter((t) => t.status === 'in_progress');
        if (inProgressTasks.length > 0) {
            // Continue with highest priority in-progress task
            const task = inProgressTasks.sort((a, b) => {
                const priorityOrder = { high: 0, medium: 1, low: 2 };
                return priorityOrder[a.priority] - priorityOrder[b.priority];
            })[0];
            return {
                type: 'continue',
                taskId: task.id,
                taskContent: task.content,
            };
        }
        // Check if any tasks are pending
        const pendingTasks = todos.filter((t) => t.status === 'pending');
        if (pendingTasks.length > 0) {
            // Start with highest priority pending task
            const task = pendingTasks.sort((a, b) => {
                const priorityOrder = { high: 0, medium: 1, low: 2 };
                return priorityOrder[a.priority] - priorityOrder[b.priority];
            })[0];
            return {
                type: 'start',
                taskId: task.id,
                taskContent: task.content,
            };
        }
        // All tasks are completed
        return { type: 'all-complete' };
    }
}
//# sourceMappingURL=todo-read.js.map