import { apiClient } from '@/infrastructure/api/api-client';
import type { Credential } from '@/domain/entities/credential';

export async function listCredentials(params?: Record<string, string>): Promise<Credential[]> {
  const query = params ? '?' + new URLSearchParams(params).toString() : '';
  return apiClient<Credential[]>(`/api/v1/inventory/credentials${query}`);
}

export async function createCredential(
  credential: Omit<Credential, 'id' | 'createdAt' | 'updatedAt' | 'associatedServers'>,
): Promise<Credential> {
  return apiClient<Credential>('/api/v1/inventory/credentials', {
    method: 'POST',
    body: credential,
  });
}

export async function updateCredential(id: string, data: Partial<Credential>): Promise<Credential> {
  return apiClient<Credential>(`/api/v1/inventory/credentials/${id}`, {
    method: 'PUT',
    body: data,
  });
}

export async function deleteCredential(id: string): Promise<void> {
  await apiClient(`/api/v1/inventory/credentials/${id}`, {
    method: 'DELETE',
  });
}
