import { z } from 'zod';
import { throwSandboxError } from "./util.js";
export const PauseResponseSchema = z.discriminatedUnion('success', [
    z.object({
        success: z.literal(false),
        message: z.string(),
        code: z.string().optional(),
    }),
    z.object({
        success: z.literal(true),
        sandboxId: z.string(),
        status: z.string(),
        checkpointId: z.string().optional(),
        terminatesAt: z.string().optional(),
    }),
]);
export const SandboxPauseParamsSchema = z.object({
    sandboxId: z.string().describe('Sandbox ID to pause'),
    orgId: z.string().optional().describe('Optional org id for CLI auth context'),
});
/**
 * Pauses a running sandbox, creating a checkpoint of its current state.
 *
 * @param client - The API client to use for the request
 * @param params - Parameters including the sandbox ID to pause
 * @returns Pause result including terminatesAt if a paused timeout is configured
 * @throws {SandboxResponseError} If the sandbox is not found or pause fails
 */
export async function sandboxPause(client, params) {
    const { sandboxId, orgId } = params;
    const queryParams = new URLSearchParams();
    if (orgId) {
        queryParams.set('orgId', orgId);
    }
    const queryString = queryParams.toString();
    const url = `/sandbox/${encodeURIComponent(sandboxId)}/pause${queryString ? `?${queryString}` : ''}`;
    const resp = await client.post(url, undefined, PauseResponseSchema);
    if (resp.success) {
        return {
            sandboxId: resp.sandboxId,
            status: resp.status,
            checkpointId: resp.checkpointId,
            terminatesAt: resp.terminatesAt,
        };
    }
    throwSandboxError(resp, { sandboxId });
}
//# sourceMappingURL=pause.js.map