import { NextRequest, NextResponse } from 'next/server' import { prisma } from '@/lib/prisma' import { requireArtist, slugify } from '@/lib/auth' export async function POST(request: NextRequest) { try { const { artist } = await requireArtist() const body = await request.json() const { title, description, coverUrl, releaseDate, albumType = 'album' } = body if (!title) { return NextResponse.json({ error: 'Title is required' }, { status: 400 }) } const slug = slugify(title) const album = await prisma.album.create({ data: { artistId: artist.id, title, slug, description, coverUrl, releaseDate: releaseDate ? new Date(releaseDate) : null, albumType, }, include: { artist: { select: { id: true, name: true, slug: true, avatarUrl: true, verified: true, }, }, _count: { select: { songs: true, }, }, }, }) return NextResponse.json(album, { status: 201 }) } catch (error) { if (error instanceof Error && error.message === 'Unauthorized') { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) } if (error instanceof Error && error.message === 'Artist profile required') { return NextResponse.json({ error: 'Artist profile required' }, { status: 403 }) } console.error('Error creating album:', error) return NextResponse.json({ error: 'Failed to create album' }, { status: 500 }) } }