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

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

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

    try {
        const count = await prisma.message.count({
            where: {
                conversation: {
                    telegramUserId: userId,
                },
                role: "user",
                isRead: false,
            },
        });

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