import { request } from '@umijs/max';
import { ServerItem, ServerParams, ServerList } from '@/pages/ServerManagement/data';

/** 获取服务器列表 GET /api/servers */
export async function queryServerList(params: ServerParams) {
    return request<ServerList>('/api/servers', {
        method: 'GET',
        params,
    });
}

/** 新增服务器 POST /api/servers */
export async function addServer(data: ServerItem) {
    return request<ServerItem>('/api/servers', {
        method: 'POST',
        data,
    });
}

/** 更新服务器 PUT /api/servers/:id */
export async function updateServer(data: Partial<ServerItem>) {
    return request<ServerItem>(`/api/servers/${data.id}`, {
        method: 'PUT',
        data,
    });
}

/** 删除服务器 DELETE /api/servers/:id */
export async function removeServer(id: string) {
    return request<{ success: boolean }>(`/api/servers/${id}`, {
        method: 'DELETE',
    });
}

/** 重启服务器 POST /api/servers/:id/restart */
export async function restartServer(id: string) {
    return request<{ success: boolean; status: string }>(`/api/servers/${id}/restart`, {
        method: 'POST',
    });
}
