import { NextRequest, NextResponse } from 'next/server';
import { tasksService } from '@/services/task-management/tasks';
import { getServerSession } from 'next-auth';
import { authOptions } from '@/lib/auth';

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

    if (!id) {
      return NextResponse.json(
        { error: 'ID de tâche requis' },
        { status: 400 }
      );
    }

    // Vérifier l'authentification
    const session = await getServerSession(authOptions);
    if (!session?.user?.id) {
      return NextResponse.json({ error: 'Non authentifié' }, { status: 401 });
    }

    const checkboxes = await tasksService.getTaskRelatedCheckboxes(
      session.user.id,
      id
    );

    return NextResponse.json({ data: checkboxes });
  } catch (error) {
    console.error('Erreur lors de la récupération des checkboxes:', error);
    return NextResponse.json(
      { error: 'Erreur lors de la récupération des checkboxes' },
      { status: 500 }
    );
  }
}
