import { b as getPathInfo, e as ensureDir, u as updateSetupStep } from '../../auth/setup/POST-DYMc2GPx.js';
import fs from 'fs';
import path from 'path';

async function handler(req, res) {
  try {
    const { storagePath, maxBackupSize, maxTotalStorage, retentionDays, autoCleanup, compressionEnabled } = req.body;
    if (!maxBackupSize || !maxTotalStorage || retentionDays === void 0 || retentionDays === null) {
      return res.status(400).json({
        success: false,
        error: "Missing required fields"
      });
    }
    const pathInfo = getPathInfo();
    ensureDir(pathInfo.appDataDir);
    const config = {
      storagePath: storagePath || pathInfo.backupsDir,
      maxBackupSize,
      maxTotalStorage,
      retentionDays,
      // 0 = keep forever
      autoCleanup: retentionDays === 0 ? false : autoCleanup,
      // Force disable if keeping forever
      compressionEnabled,
      updatedAt: (/* @__PURE__ */ new Date()).toISOString()
    };
    const configPath = path.join(pathInfo.appDataDir, "storage-config.json");
    fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
    updateSetupStep("storage", true);
    res.json({
      success: true,
      message: "Storage configuration saved successfully",
      config
    });
  } catch (error) {
    console.error("Failed to save storage limits:", error);
    res.status(500).json({
      success: false,
      error: "Failed to save storage limits",
      message: String(error)
    });
  }
}

export { handler as h };
