import { apiClient } from '../api/api-client';
import type { AgentConfigRepository } from '@/domain/repositories/agent-config.repository';
import type { AgentConfigDto } from '@/application/dto/agent-config.dto';

export const apiAgentConfigRepository: AgentConfigRepository = {
  async getConfig() {
    return apiClient<AgentConfigDto>('/api/v1/agent-config');
  },

  async saveConfig(config) {
    await apiClient('/api/v1/agent-config', {
      method: 'PUT',
      body: config,
    });
  },

  async switchEngine(engineType) {
    await apiClient('/api/v1/agent-config/engine', {
      method: 'PUT',
      body: { engineType },
    });
  },

  async getSystemPrompt() {
    const config = await apiClient<AgentConfigDto>('/api/v1/agent-config');
    return config.systemPrompt ?? '';
  },

  async updateSystemPrompt(prompt) {
    await apiClient('/api/v1/agent-config/system-prompt', {
      method: 'PUT',
      body: { prompt },
    });
  },

  async getHooks() {
    return apiClient('/api/v1/agent-config/hooks');
  },

  async updateHook(hook) {
    await apiClient(`/api/v1/agent-config/hooks/${hook.id}`, {
      method: 'PUT',
      body: hook,
    });
  },
};
