import { f as defineAdminEventHandler, h as requireAdminRole, t as getAdminActor, q as readBody, b5 as updateBackupScheduleConfig, b6 as ensureSchedule, b7 as getSchedules, b8 as deleteSchedule, c as createError } from '../../../../nitro/nitro.mjs';
import 'node:crypto';
import 'jsonwebtoken';
import 'node:fs';
import 'node:module';
import 'node:path';
import 'node:url';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'pino';
import 'drizzle-orm/better-sqlite3';
import 'drizzle-orm/node-postgres';
import 'drizzle-orm/mysql2';
import 'better-sqlite3';
import 'pg';
import 'mysql2/promise';
import 'drizzle-orm';
import 'fs';
import 'path';
import 'prom-client';
import 'bcryptjs';
import '@node-rs/argon2';
import 'node:async_hooks';
import 'crypto';
import 'node:dns';
import 'node:util';
import 'node:net';
import 'fs/promises';
import 'url';
import 'semver';

const schedule_put = defineAdminEventHandler("admin:backups:schedule:update", async (event) => {
  var _a;
  try {
    await requireAdminRole(event, ["super-admin"]);
    const actor = getAdminActor(event);
    const body = (_a = await readBody(event)) != null ? _a : {};
    const config = await updateBackupScheduleConfig(body, actor);
    if (config.enabled) {
      await ensureSchedule({
        name: "backup.scheduled",
        cronExpression: config.cronExpression,
        queue: "backup",
        enabled: true
      });
    } else {
      const schedules = await getSchedules();
      const existing = schedules.find((s) => s.name === "backup.scheduled");
      if (existing) {
        await deleteSchedule(existing.id);
      }
    }
    return {
      success: true,
      data: config
    };
  } catch (error) {
    if (error && typeof error === "object" && "statusCode" in error) {
      throw error;
    }
    if (error instanceof Error && error.message.includes("Invalid cron expression")) {
      throw createError({
        statusCode: 400,
        statusMessage: "Bad Request",
        message: error.message
      });
    }
    console.error("[PUT /api/admin/backups/schedule] Error:", error);
    throw createError({
      statusCode: 500,
      statusMessage: "Failed to update backup schedule",
      message: error instanceof Error ? error.message : "Unknown error"
    });
  }
});

export { schedule_put as default };
//# sourceMappingURL=schedule.put.mjs.map
