import { NextResponse } from 'next/server'
import { navidromeGet } from '@/lib/navidrome'

export async function POST(request: Request) {
  try {
    const { name, songId } = await request.json()
    if (!name) {
      return NextResponse.json({ error: 'name required' }, { status: 400 })
    }

    const params: Record<string, string> = { name }
    if (songId) params.songId = songId

    await navidromeGet('createPlaylist.view', params)
    return NextResponse.json({ success: true })
  } catch (error) {
    console.error('Create playlist error:', error)
    return NextResponse.json({ error: 'Failed to create playlist' }, { status: 502 })
  }
}
