/**
 * GET /api/social/inbox
 * List inbox conversations across connected accounts
 */

import { NextRequest, NextResponse } from "next/server";
import { auth } from "@/lib/auth";
import { SocialInboxService } from "@/lib/services/social-inbox.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 conversations = await SocialInboxService.getConversations(
      session.user.id,
    );

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