import { apiClient } from '../api/api-client';
import type { ServerRepository } from '@/domain/repositories/server.repository';
import type { Server } from '@/domain/entities/server';

export const apiServerRepository: ServerRepository = {
  async list(params) {
    const query = params ? '?' + new URLSearchParams(params).toString() : '';
    return apiClient<Server[]>(`/api/v1/inventory/servers${query}`);
  },

  async getById(id) {
    return apiClient<Server>(`/api/v1/inventory/servers/${id}`);
  },

  async create(server) {
    return apiClient<Server>('/api/v1/inventory/servers', {
      method: 'POST',
      body: server,
    });
  },

  async update(id, data) {
    return apiClient<Server>(`/api/v1/inventory/servers/${id}`, {
      method: 'PUT',
      body: data,
    });
  },

  async remove(id) {
    await apiClient(`/api/v1/inventory/servers/${id}`, {
      method: 'DELETE',
    });
  },
};
