/**
 * Todo Tool Adapters
 *
 * ITool-compliant adapters for TodoTool operations.
 * These adapters wrap the existing TodoTool methods to conform
 * to the formal ITool interface for use with the FormalToolRegistry.
 */
import { TodoTool } from '../todo-tool.js';
// ============================================================================
// Shared TodoTool Instance
// ============================================================================
let todoInstance = null;
function getTodo() {
    if (!todoInstance) {
        todoInstance = new TodoTool();
    }
    return todoInstance;
}
/**
 * Reset the shared TodoTool instance (for testing)
 */
export function resetTodoInstance() {
    todoInstance = null;
}
// ============================================================================
// CreateTodoListTool
// ============================================================================
/**
 * CreateTodoListTool - ITool adapter for creating todo lists
 */
export class CreateTodoListTool {
    name = 'create_todo_list';
    description = 'Create a new todo list with tasks';
    async execute(input) {
        const todos = input.todos;
        return await getTodo().createTodoList(todos);
    }
    getSchema() {
        return {
            name: this.name,
            description: this.description,
            parameters: {
                type: 'object',
                properties: {
                    todos: {
                        type: 'array',
                        description: 'Array of todo items to create',
                        items: {
                            type: 'object',
                            description: 'Todo item with id, content, status, and priority',
                        },
                    },
                },
                required: ['todos'],
            },
        };
    }
    validate(input) {
        if (typeof input !== 'object' || input === null) {
            return { valid: false, errors: ['Input must be an object'] };
        }
        const data = input;
        if (!Array.isArray(data.todos)) {
            return { valid: false, errors: ['todos must be an array'] };
        }
        for (let i = 0; i < data.todos.length; i++) {
            const todo = data.todos[i];
            if (!todo.id || !todo.content || !todo.status || !todo.priority) {
                return { valid: false, errors: [`Todo at index ${i} must have id, content, status, and priority`] };
            }
        }
        return { valid: true };
    }
    getMetadata() {
        return {
            name: this.name,
            description: this.description,
            category: 'planning',
            keywords: ['todo', 'task', 'list', 'create', 'plan'],
            priority: 5,
            modifiesFiles: false,
            makesNetworkRequests: false,
        };
    }
    isAvailable() {
        return true;
    }
}
// ============================================================================
// GetTodoListTool
// ============================================================================
/**
 * GetTodoListTool - ITool adapter for viewing todo lists
 */
export class GetTodoListTool {
    name = 'get_todo_list';
    description = 'Get the current todo list to see all tasks and their status';
    async execute(input) {
        const filter = input.filter;
        const result = await getTodo().viewTodoList();
        // Apply filter if specified
        if (filter && filter !== 'all' && result.success && result.output) {
            const lines = result.output.split('\n');
            const filtered = lines.filter(line => {
                if (filter === 'pending')
                    return line.includes('⬜') || line.includes('pending');
                if (filter === 'in_progress')
                    return line.includes('🔄') || line.includes('in_progress');
                if (filter === 'completed')
                    return line.includes('✅') || line.includes('completed');
                return true;
            });
            return { success: true, output: filtered.join('\n') || 'No todos matching filter' };
        }
        return result;
    }
    getSchema() {
        return {
            name: this.name,
            description: this.description,
            parameters: {
                type: 'object',
                properties: {
                    filter: {
                        type: 'string',
                        description: 'Filter by status: all, pending, in_progress, completed',
                    },
                },
                required: [],
            },
        };
    }
    validate(input) {
        if (typeof input !== 'object' || input === null) {
            return { valid: false, errors: ['Input must be an object'] };
        }
        return { valid: true };
    }
    getMetadata() {
        return {
            name: this.name,
            description: this.description,
            category: 'planning',
            keywords: ['todo', 'task', 'list', 'view', 'get', 'show'],
            priority: 5,
            modifiesFiles: false,
            makesNetworkRequests: false,
        };
    }
    isAvailable() {
        return true;
    }
}
// ============================================================================
// UpdateTodoListTool
// ============================================================================
/**
 * UpdateTodoListTool - ITool adapter for updating todo lists
 */
export class UpdateTodoListTool {
    name = 'update_todo_list';
    description = 'Update existing todo items (change status, content, or priority)';
    async execute(input) {
        const updates = input.updates;
        return await getTodo().updateTodoList(updates);
    }
    getSchema() {
        return {
            name: this.name,
            description: this.description,
            parameters: {
                type: 'object',
                properties: {
                    updates: {
                        type: 'array',
                        description: 'Array of updates to apply',
                        items: {
                            type: 'object',
                            description: 'Update with id and fields to change',
                        },
                    },
                },
                required: ['updates'],
            },
        };
    }
    validate(input) {
        if (typeof input !== 'object' || input === null) {
            return { valid: false, errors: ['Input must be an object'] };
        }
        const data = input;
        if (!Array.isArray(data.updates)) {
            return { valid: false, errors: ['updates must be an array'] };
        }
        for (let i = 0; i < data.updates.length; i++) {
            const update = data.updates[i];
            if (!update.id) {
                return { valid: false, errors: [`Update at index ${i} must have an id`] };
            }
        }
        return { valid: true };
    }
    getMetadata() {
        return {
            name: this.name,
            description: this.description,
            category: 'planning',
            keywords: ['todo', 'task', 'update', 'status', 'progress'],
            priority: 5,
            modifiesFiles: false,
            makesNetworkRequests: false,
        };
    }
    isAvailable() {
        return true;
    }
}
// ============================================================================
// Factory Function
// ============================================================================
/**
 * Create all todo tool instances
 */
export function createTodoTools() {
    return [
        new CreateTodoListTool(),
        new GetTodoListTool(),
        new UpdateTodoListTool(),
    ];
}
//# sourceMappingURL=todo-tools.js.map