import { apiGet, apiPost } from "./client";
import type { AvatarSettings, EnvironmentInfo, ExtensionInfo, McpServerInfo, McpToolInfo, SettingsData, SkillInfo } from "../types/events";

export function fetchSettings(): Promise<SettingsData> {
	return apiGet("/api/settings");
}

export function toggleSkill(path: string, enabled: boolean): Promise<{ ok?: boolean; skill?: SkillInfo }> {
	return apiPost("/api/settings/skills/toggle", { path, enabled });
}

export function toggleExtension(
	path: string,
	enabled: boolean,
): Promise<{ ok?: boolean; extension?: ExtensionInfo }> {
	return apiPost("/api/settings/extensions/toggle", { path, enabled });
}

export function toggleMcpServer(
	server: string,
	enabled: boolean,
): Promise<{ ok?: boolean; server?: McpServerInfo }> {
	return apiPost("/api/settings/mcp/server/toggle", { server, enabled });
}

export function toggleMcpTool(
	server: string,
	tool: string,
	enabled: boolean,
): Promise<{ ok?: boolean; tool?: McpToolInfo }> {
	return apiPost("/api/settings/mcp/tool/toggle", { server, tool, enabled });
}

export function fetchAvatars(): Promise<AvatarSettings> {
	return apiGet("/api/avatars");
}

export function reloadSettings(): Promise<{ ok?: boolean }> {
	return apiPost("/api/settings/reload");
}

export function saveSystemPrompt(systemPrompt: string): Promise<{ systemPromptPath?: string }> {
	return apiPost("/api/settings/system-prompt", { systemPrompt });
}

export function saveModelsConfig(modelsConfig: string): Promise<{ modelsConfigPath?: string }> {
	return apiPost("/api/settings/models-config", { modelsConfig });
}

export function saveAvatars(avatars: AvatarSettings): Promise<AvatarSettings & { ok?: boolean }> {
	return apiPost("/api/settings/avatars", avatars);
}

export function fetchEnvironment(): Promise<EnvironmentInfo> {
	return apiGet("/api/environment");
}

export function fetchTerminalInfo(): Promise<{ repoRoot?: string; platform?: string }> {
	return apiGet("/api/terminal");
}
