import { createProviderWithToken } from "../utils/providerFactory.js";
import { getErrorMessage, mapProviderError } from "../utils/errorMapper.js";
import { getAdapter } from "../adapters/factory.js";
import { adapterDisplayName } from "../adapters/shared.js";
export async function updateServer(server, apiToken, platform) {
    const adapter = getAdapter(platform);
    const displayName = adapterDisplayName(adapter);
    // Check server status via provider API (skip for manual servers)
    if (!server.id.startsWith("manual-")) {
        try {
            const providerInstance = createProviderWithToken(server.provider, apiToken);
            const status = await providerInstance.getServerStatus(server.id);
            if (status !== "running") {
                return { success: false, displayName, error: `Server is not running (status: ${status})` };
            }
        }
        catch (error) {
            const hint = mapProviderError(error, server.provider);
            return {
                success: false,
                displayName,
                error: getErrorMessage(error),
                ...(hint ? { hint } : {}),
            };
        }
    }
    // Call adapter update
    try {
        const result = await adapter.update(server.ip);
        return {
            success: result.success,
            output: result.output,
            error: result.error,
            displayName,
        };
    }
    catch (error) {
        return {
            success: false,
            displayName,
            error: getErrorMessage(error),
        };
    }
}
//# sourceMappingURL=update.js.map