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

export async function DELETE(request: NextRequest, { params }: { params: Promise<{ id: string; trackId: string }> }) {
  try {
    const { id, trackId } = await params

    await sql`
      DELETE FROM downloaded_tracks
      WHERE user_id = ${id} AND track_id = ${trackId}
    `

    return NextResponse.json({ success: true })
  } catch (error) {
    console.error("Delete download error:", error)
    return NextResponse.json({ error: "Erreur lors de la suppression" }, { status: 500 })
  }
}
