import { c as createStorageProvider } from '../../backup/delete/_backupId_/DELETE-CSeC5rJf.js';

async function handler(req, res) {
  try {
    const { storageType, config } = req.body;
    const validTypes = ["local", "s3", "gcs", "azure"];
    if (!validTypes.includes(storageType)) {
      return res.status(400).json({
        success: false,
        error: "Invalid storage type",
        validTypes
      });
    }
    if (!config || typeof config !== "object") {
      return res.status(400).json({
        success: false,
        error: "Configuration object is required"
      });
    }
    try {
      const provider = createStorageProvider({ type: storageType, config });
      const testData = Buffer.from("MyCloudVault connection test");
      const testPath = `test-${Date.now()}.txt`;
      await provider.upload(testData, testPath);
      const exists = await provider.exists(testPath);
      await provider.delete(testPath);
      res.json({
        success: true,
        message: "Storage provider connection successful",
        tests: {
          upload: true,
          exists,
          delete: true
        }
      });
    } catch (error) {
      return res.status(400).json({
        success: false,
        error: "Storage provider connection failed",
        message: String(error)
      });
    }
  } catch (error) {
    console.error("Error testing storage provider:", error);
    res.status(500).json({
      success: false,
      error: "Failed to test storage provider",
      message: String(error)
    });
  }
}

export { handler as h };
