import { NextRequest, NextResponse } from "next/server";
import { getServerSession } from "next-auth";
import { authOptions } from "@/app/api/auth/authOptions";
import { prisma } from "@/lib/prisma";
import { NotificationType } from "@prisma/client";

export async function POST(req: NextRequest) {
  try {
    const session = await getServerSession(authOptions);
    if (!session?.user) {
      return NextResponse.json({ error: "Accès refusé" }, { status: 403 });
    }

    // Créer quelques notifications de test
    const testNotifications = [
      {
        userId: parseInt(session.user.id),
        type: NotificationType.TASK_ASSIGNED,
        content: "Une nouvelle tâche vous a été assignée",
        isRead: false,
        relatedType: "task",
        relatedId: 1
      },
      {
        userId: parseInt(session.user.id),
        type: NotificationType.CLIENT_UPDATE,
        content: "Un client a été mis à jour",
        isRead: false,
        relatedType: "client",
        relatedId: 1
      },
      {
        userId: parseInt(session.user.id),
        type: NotificationType.SYSTEM_ALERT,
        content: "Maintenance prévue ce soir à 22h",
        isRead: false
      },
      {
        userId: parseInt(session.user.id),
        type: NotificationType.TRANSFER,
        content: "Un transfert a été effectué",
        isRead: false,
        relatedType: "client",
        relatedId: 2
      },
      {
        userId: parseInt(session.user.id),
        type: NotificationType.DOCUMENT_UPLOAD,
        content: "Un nouveau document a été uploadé",
        isRead: false,
        relatedType: "document",
        relatedId: 1
      }
    ];

    const createdNotifications = await Promise.all(
      testNotifications.map(notification =>
        prisma.notification.create({
          data: notification
        })
      )
    );

    return NextResponse.json({ 
      success: true, 
      message: `${createdNotifications.length} notifications de test créées`,
      notifications: createdNotifications
    });

  } catch (error) {
    console.error('Erreur lors de la création des notifications de test:', error);
    return NextResponse.json(
      { error: "Erreur lors de la création des notifications de test" },
      { status: 500 }
    );
  }
} 