import { NextResponse } from "next/server";
import { auth } from "@/auth";
import { getPinnedMessages } from "@/lib/chat/queries";

export async function GET(
  _req: Request,
  { params }: { params: Promise<{ channelId: string }> },
) {
  const session = await auth();
  if (!session?.user) {
    return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
  }
  const { channelId } = await params;
  const pinned = await getPinnedMessages(channelId, session.user.id);
  if (pinned === null) {
    return NextResponse.json({ error: "Not found" }, { status: 404 });
  }
  return NextResponse.json({ pinned });
}
