import { NextRequest, NextResponse } from "next/server"; import { backupService } from "@/services/backup.service"; import { requireAuth } from "@/lib/auth-utils"; export async function POST(_request: NextRequest) { const authError = await requireAuth(); if (authError) return authError; try { // Check if automatic backup should run const shouldRun = await backupService.shouldRunAutomaticBackup(); if (!shouldRun) { return NextResponse.json({ success: true, skipped: true, message: "Backup not due yet", }); } // Create backup const backup = await backupService.createBackup(); return NextResponse.json({ success: true, data: backup, message: backup.skipped ? "Backup skipped - no changes detected" : "Automatic backup created", }); } catch (error) { console.error("Error creating automatic backup:", error); return NextResponse.json( { success: false, error: error instanceof Error ? error.message : "Failed to create automatic backup", }, { status: 500 }, ); } }