001/*
002 * SPDX-License-Identifier: Apache-2.0
003 *
004 * Copyright 2025-2026 The Enola <https://enola.dev> Authors
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *     https://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package dev.enola.tool.todo.adk;
019
020import com.google.adk.tools.Annotations.Schema;
021import com.google.adk.tools.BaseTool;
022import com.google.adk.tools.FunctionTool;
023import com.google.common.collect.ImmutableMap;
024
025import dev.enola.ai.adk.tool.Tools;
026import dev.enola.common.SuccessOrError;
027import dev.enola.tool.todo.ToDo;
028import dev.enola.tool.todo.ToDoRepository;
029
030import java.io.IOException;
031import java.util.Map;
032
033public class ToDoTool {
034
035    // TODO complete_todo ... but how will the LLM identify the item by id?
036
037    private final ToDoRepository toDoRepository;
038
039    public ToDoTool(ToDoRepository toDoRepository) {
040        this.toDoRepository = toDoRepository;
041    }
042
043    public Map<String, BaseTool> createToolSet() {
044        return ImmutableMap.of(
045                "add_todo",
046                FunctionTool.create(this, "addToDo"),
047                "list_todos",
048                FunctionTool.create(this, "listToDos"));
049    }
050
051    @Schema(description = "List all of my ToDo Task items")
052    public Map<String, ?> listToDos() {
053        var items = toDoRepository.list();
054        return Tools.toMap(SuccessOrError.success(items));
055    }
056
057    @Schema(description = "Add a new ToDo Task item")
058    public Map<String, ?> addToDo(
059            @Schema(description = "The title of the ToDo Task item") String title,
060            @Schema(description = "The optional description of the ToDo Task item")
061                    String description)
062            throws IOException {
063        var builder = ToDo.builder().title(title);
064        if (description != null) {
065            builder.description(description);
066        }
067        toDoRepository.store(builder.build());
068        return Tools.successMap("Successfully added the ToDo item.");
069    }
070}