/**
 * GET /api/social/calendar/drafts
 * Get all draft posts
 */

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) {
  try {
    const session = await auth();
    if (!session?.user?.id) {
      return NextResponse.json(
        { success: false, error: "Unauthorized" },
        { status: 401 },
      );
    }

    const drafts = await SocialCalendarService.getDrafts(session.user.id);

    return NextResponse.json({ drafts, success: true });
  } catch (error) {
    logger.error("Failed to get drafts", { error });
    return NextResponse.json(
      { success: false, error: "Failed to get drafts" },
      { status: 500 },
    );
  }
}
