import client from '../client';

export interface AiAgentConfig {
  model: string;
  temperature: number;
  max_tokens: number;
  max_iterations: number;
  system_prompt: string;
}

export interface AiAnalysisDefaults {
  model: string;
  temperature: number;
  max_tokens: number;
}

export interface AiProviderConfig {
  provider_type: string;
  enabled: boolean;
  base_url: string;
  api_key: string;
  model: string;
}

export interface AiConfig {
  agent: AiAgentConfig;
  analysis_defaults: AiAnalysisDefaults;
  default_provider: string;
  providers: Record<string, AiProviderConfig>;
}

export const aiConfigApi = {
  get: async () => {
    const resp = await client.get('/ai/config');
    return resp.data.data as AiConfig;
  },
  getDefaults: async () => {
    const resp = await client.get('/ai/config/defaults');
    return resp.data.data as AiConfig;
  },
  update: async (config: AiConfig) => {
    const resp = await client.put('/ai/config', { config });
    return resp.data.data as AiConfig;
  },
};
