import { type NextRequest, NextResponse } from "next/server"
import { getAdminUser } from "@/lib/admin-auth"
import { sql } from "@/lib/db"

export async function POST(request: NextRequest, { params }: { params: Promise<{ id: string }> }) {
  try {
    const adminId = await getAdminUser(request)
    if (!adminId) {
      return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
    }

    const { id } = await params

    const backup = await sql`SELECT * FROM backups WHERE id = ${id}`
    if (backup.length === 0) {
      return NextResponse.json({ error: "Backup not found" }, { status: 404 })
    }

    return NextResponse.json({
      success: true,
      message: "Restore initiated",
      backup_id: id,
    })
  } catch (error) {
    console.error("Error restoring backup:", error)
    return NextResponse.json({ error: "Failed to restore backup" }, { status: 500 })
  }
}
