import { createProviderWithToken } from "../utils/providerFactory.js";
import { getErrorMessage, mapProviderError } from "../utils/errorMapper.js";
// ─── Async Wrappers ──────────────────────────────────────────────────────────
export async function createSnapshot(server, apiToken) {
    try {
        const provider = createProviderWithToken(server.provider, apiToken);
        // Best-effort cost estimate
        let costEstimate;
        try {
            costEstimate = await provider.getSnapshotCostEstimate(server.id);
        }
        catch {
            costEstimate = "unknown";
        }
        const snapshotName = `kastell-${Date.now()}`;
        const snapshot = await provider.createSnapshot(server.id, snapshotName);
        return { success: true, snapshot, costEstimate };
    }
    catch (error) {
        const hint = mapProviderError(error, server.provider);
        return {
            success: false,
            error: getErrorMessage(error),
            ...(hint ? { hint } : {}),
        };
    }
}
export async function listSnapshots(server, apiToken) {
    try {
        const provider = createProviderWithToken(server.provider, apiToken);
        const snapshots = await provider.listSnapshots(server.id);
        return { snapshots };
    }
    catch (error) {
        const hint = mapProviderError(error, server.provider);
        return {
            snapshots: [],
            error: getErrorMessage(error),
            ...(hint ? { hint } : {}),
        };
    }
}
export async function deleteSnapshot(server, apiToken, snapshotId) {
    try {
        const provider = createProviderWithToken(server.provider, apiToken);
        await provider.deleteSnapshot(snapshotId);
        return { success: true };
    }
    catch (error) {
        const hint = mapProviderError(error, server.provider);
        return {
            success: false,
            error: getErrorMessage(error),
            ...(hint ? { hint } : {}),
        };
    }
}
export async function restoreSnapshot(server, apiToken, snapshotId) {
    try {
        const provider = createProviderWithToken(server.provider, apiToken);
        await provider.restoreSnapshot(server.id, snapshotId);
        return { success: true };
    }
    catch (error) {
        const hint = mapProviderError(error, server.provider);
        return {
            success: false,
            error: getErrorMessage(error),
            ...(hint ? { hint } : {}),
        };
    }
}
//# sourceMappingURL=snapshot.js.map