import client from '../client';

export interface OciConfigFull {
  id: string;
  user_id: string;
  tenancy_name: string;
  tenancy_ocid: string;
  user_ocid: string;
  fingerprint: string;
  region: string;
  compartment_id?: string;
  ssh_public_key?: string;
  ssh_public_key_preview?: string;
  auth_type: 'api_key' | 'session_token';
  created_at: string;
}

export interface OciTestResult {
  status: 'success' | 'error';
  message: string;
  data?: unknown;
}

export const ociApi = {
  list: () =>
    client.get('/oci/configs') as unknown as Promise<OciConfigFull[]>,

  create: (fd: FormData) =>
    client.post('/oci/config', fd, { headers: { 'Content-Type': 'multipart/form-data' } }) as unknown as Promise<{ id: string; tenancy_name: string; region: string }>,

  update: (id: string, fd: FormData) =>
    client.put(`/oci/configs/${id}`, fd, { headers: { 'Content-Type': 'multipart/form-data' } }) as unknown as Promise<{ id: string; tenancy_name: string; region: string }>,

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

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