import { NextRequest, NextResponse } from 'next/server' import { requireAuth } from '@/lib/auth' import { getPreviousInQueue, playSong } from '@/lib/player' export async function POST(request: NextRequest) { try { const user = await requireAuth() const previousSongId = await getPreviousInQueue(user.id) if (!previousSongId) { return NextResponse.json( { error: 'No previous song in queue' }, { status: 404 } ) } await playSong(user.id, previousSongId, 'queue') return NextResponse.json( { message: 'Playing previous song', songId: previousSongId }, { status: 200 } ) } catch (error) { console.error('Previous song error:', error) if (error instanceof Error && error.message === 'Unauthorized') { return NextResponse.json( { error: 'Unauthorized' }, { status: 401 } ) } return NextResponse.json( { error: 'Failed to play previous song' }, { status: 500 } ) } }