package edu.uniceub.calendar_man.chatworkflowmanager.open_ai.functions;

import com.theokanning.openai.completion.chat.ChatFunction;
import edu.uniceub.calendar_man.chatworkflowmanager.models.Event;
import edu.uniceub.calendar_man.chatworkflowmanager.open_ai.functions.contexts.GetCurrentDateResponse;
import edu.uniceub.calendar_man.chatworkflowmanager.open_ai.functions.contexts.GetEventsRequest;
import java.time.LocalDateTime;
import java.util.List;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public final class FunctionUtils {

  final Logger LOGGER = LoggerFactory.getLogger(FunctionUtils.class);

  private FunctionUtils() {}

  public static final List<String> ASSISTANT_ACTION_FUNCTIONS =
      List.of("get_calendar_context", "schedule_event", "get_current_date");

  public static ChatFunction getCalendarEventsFunction(
      final Function<GetEventsRequest, Object> getEvents) {
    return ChatFunction.builder()
        .name("get_calendar_context")
        .description("Accesses the user's calendar and gets the events for the given date.")
        .executor(GetEventsRequest.class, getEvents)
        .build();
  }

  public static ChatFunction scheduleNewEvent(final Function<Event, Object> scheduleEvent) {

    return ChatFunction.builder()
        .name("schedule_event")
        .description("Schedules a new event to the user's calendar.")
        .executor(Event.class, scheduleEvent)
        .build();
  }

  public static ChatFunction getCurrentDate() {
    return ChatFunction.builder()
        .name("get_current_date")
        .description("Returns the current date.")
        .executor(
            Object.class, empty -> GetCurrentDateResponse.fromDate(LocalDateTime.now().toString()))
        .build();
  }
}

com.theokanning.openai.completion.chat.ChatFunction.builder
[((954, 1177), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((954, 1160), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((954, 1107), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((954, 1014), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((1289, 1476), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((1289, 1459), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((1289, 1413), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((1289, 1343), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((1542, 1784), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((1542, 1767), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((1542, 1648), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((1542, 1598), 'com.theokanning.openai.completion.chat.ChatFunction.builder'), ((1735, 1765), 'java.time.LocalDateTime.now')]