import clientPromise, { database, objectId } from "@/db.config";
import { NextResponse } from "next/server";

export async function POST(request) {
  try {
    const { searchParams } = new URL(request.url);
    const post_id = searchParams.get("post_id");
    const uid = searchParams.get("uid");

    const client = await clientPromise;
    const db = client.db(database);
    const postslock = db.collection("posts_lock");

    const result = await postslock.deleteOne({
      uid,
      post_id: objectId(post_id),
    });

    return NextResponse.json({ status: "success" }, { status: 200 });
  } catch (error) {
    console.log(error);
    return NextResponse.json({ error: error.message }, { status: 500 });
  }
}
