import { ULTICAL_APP_NAME } from "@/lib/suite/page-metadata"

export type UltiAiToolGroup = {
  id: string
  label: string
  description: string
}

/** Tool groups exposed to UltiAI via MCP (X-Ulti-Enabled-Tools). */
export const ULTIAI_TOOL_GROUPS: UltiAiToolGroup[] = [
  {
    id: "mail",
    label: "Mail",
    description: "Recherche, lecture, envoi, libellés et suppression de messages.",
  },
  {
    id: "drive",
    label: "Drive",
    description: "Fichiers, dossiers, partages et déplacements.",
  },
  {
    id: "contacts",
    label: "Contacts",
    description: "Carnets d'adresses et fiches contacts.",
  },
  {
    id: "agenda",
    label: ULTICAL_APP_NAME,
    description: "Calendriers, événements, invitations et visioconférence.",
  },
  {
    id: "search",
    label: "Recherche suite",
    description: "Index unifié mail, drive et contacts (pas le web public).",
  },
  {
    id: "web_search",
    label: "Recherche web",
    description:
      "Recherche en ligne (Brave, Bing, SearXNG, DuckDuckGo, API JSON). Même réglages que contacts — onglet Recherche.",
  },
]

export const DEFAULT_ULTIAI_ENABLED_TOOLS = ULTIAI_TOOL_GROUPS.map((group) => group.id)

export function toggleUltiAiToolGroup(
  enabledTools: string[],
  groupId: string,
  enabled: boolean,
): string[] {
  const set = new Set(enabledTools)
  if (enabled) set.add(groupId)
  else set.delete(groupId)
  return ULTIAI_TOOL_GROUPS.map((group) => group.id).filter((id) => set.has(id))
}
