// app/api/users/[userId]/conversations/[conversationId]/read/route.ts
import { NextResponse } from "next/server";
;

import { prisma } from '@/lib/prisma';

export async function POST(
    req: Request,
    { params }: { params: Promise<{ userId: string; conversationId: string }> }
) {
    const { conversationId } = await params;

    try {
        // Mark all user messages in this conversation as read
        await prisma.message.updateMany({
            where: {
                conversationId,
                role: "user",
                isRead: false,
            },
            data: {
                isRead: true,
            },
        });

        return NextResponse.json({ success: true });
    } catch (error) {
        console.error("[MARK_READ]", error);
        return NextResponse.json({ error: "خطای سرور داخلی" }, { status: 500 });
    }
}