import { api } from './api';
import type { ToolConfig, ToolTestResult } from '../types/toolConfig.types';

interface ApiResponse<T> {
  success: boolean;
  data: T;
}

export const toolConfigApi = {
  get: (tool: string): Promise<ToolConfig> =>
    api.get<ApiResponse<ToolConfig>>(`/api/admin/tools/config/${tool}`).then(r => r.data.data),

  update: (tool: string, config: Partial<ToolConfig>): Promise<void> =>
    api.put(`/api/admin/tools/config/${tool}`, config).then(() => {}),

  test: (tool: string, config?: Partial<ToolConfig>): Promise<ToolTestResult> =>
    api.post<ApiResponse<ToolTestResult>>(`/api/admin/tools/config/${tool}/test`, config ?? {}).then(r => r.data.data),
};
