/**
 * DELETE /api/social/calendar/[itemId]
 * Delete a scheduled/draft post
 */

import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { SocialCalendarService } from "@/lib/services/social-calendar.service";
import { logger } from "@/lib/logger";
export async function GET(
  _request: NextRequest,
  _context: { params: Promise<{ itemId: string }> },
) {
  // Convex-only — calendar item not yet migrated, return null
  return NextResponse.json({ item: null, success: true });
}

export async function DELETE(
  _request: NextRequest,
  { params }: { params: Promise<{ itemId: string }> },
) {
  try {
    const session = await auth();
    if (!session?.user?.id) {
      return NextResponse.json(
        { success: false, error: "Unauthorized" },
        { status: 401 },
      );
    }

    const { itemId } = await params;
    await SocialCalendarService.deleteScheduledPost(session.user.id, itemId);
    return NextResponse.json({ success: true, message: "Post deleted" });
  } catch (error) {
    logger.error("Failed to delete scheduled post", { error });
    const msg = error instanceof Error ? error.message : "Failed to delete";
    return NextResponse.json({ success: false, error: msg }, { status: 500 });
  }
}
