import { NextResponse, NextRequest } from 'next/server';
import { prisma } from '@/lib/prisma';

export async function GET(
  request: NextRequest,
  context: { params: Promise<{ id: string }> }
) {
  try {
    const { id } = await context.params;
    const label = await prisma.cancelledLabel.findFirst({
      where: {
        OR: [
          { id },
          { orderLineId: id },
          { uniqueCode: id },
          { boxNumber: id }
        ]
      }
    });

    if (!label) {
      return NextResponse.json({ error: 'Etiqueta cancelada no encontrada' }, { status: 404 });
    }

    return NextResponse.json({
      success: true,
      label
    });
  } catch (error: any) {
    console.error('Error fetching single cancelled label:', error);
    return NextResponse.json({ error: error.message || 'Error fetching cancelled label' }, { status: 500 });
  }
}
