import { NextResponse } from "next/server";
import { cookies } from "next/headers";

// This is your DELETE handler for the logout endpoint
export async function DELETE() {
  try {
    // Clear the authentication cookie.
    // This MUST match the name of the cookie set during login.
    // In your login handler, the cookie is named "auth_token".
    const cookieStore = await cookies();
    cookieStore.delete("auth_token");

    return NextResponse.json(
      { success: true, message: "Logged out successfully" },
      { status: 200 },
    );
  } catch (error) {
    console.error("Logout API error:", error);
    return NextResponse.json(
      { success: false, message: "Internal server error during logout" },
      { status: 500 },
    );
  }
}
