import client from '../client';

export interface GenAiConfigFull {
  id: string;
  name: string;
  oci_config_id: string;
  model_id: string;
  model_ocid?: string;
  compartment_id: string;
  genai_region: string;
  endpoint?: string;
  serving_type: string;
  dedicated_endpoint_id?: string;
  temperature: number;
  max_tokens: number;
  top_p: number;
  top_k: number;
  frequency_penalty: number;
  presence_penalty: number;
  reasoning_effort?: string;
  is_default: boolean;
  created_at?: string;
}

export interface GenAiConfigPayload {
  name: string;
  oci_config_id: string;
  model_id: string;
  model_ocid?: string | null;
  compartment_id: string;
  genai_region: string;
  endpoint?: string | null;
  serving_type?: string;
  dedicated_endpoint_id?: string | null;
  temperature?: number;
  max_tokens?: number;
  top_p?: number;
  top_k?: number;
  frequency_penalty?: number;
  presence_penalty?: number;
  reasoning_effort?: string | null;
  is_default?: boolean;
}

export interface GenAiTestResult {
  status: 'success' | 'error';
  message: string;
  response?: string;
}

export const genaiApi = {
  list: () =>
    client.get('/genai/configs') as unknown as Promise<GenAiConfigFull[]>,

  create: (body: GenAiConfigPayload) =>
    client.post('/genai/config', body) as unknown as Promise<{ id: string; model_id: string; endpoint: string }>,

  update: (id: string, body: GenAiConfigPayload) =>
    client.put(`/genai/configs/${id}`, body) as unknown as Promise<{ id: string; model_id: string; endpoint: string }>,

  remove: (id: string) =>
    client.delete(`/genai/configs/${id}`) as unknown as Promise<{ ok: boolean }>,

  test: (id: string) =>
    client.post(`/genai/test/${id}`) as unknown as Promise<GenAiTestResult>,
};
