import { apiError, requireOwner } from "@/lib/auth";
import { ensureSchema, rawDb } from "@/lib/db";

export async function DELETE(request: Request, context: { params: Promise<{ id: string }> }) {
  try {
    const ownerId = requireOwner(request);
    const { id } = await context.params;
    await ensureSchema();
    const result = await rawDb().prepare("DELETE FROM social_accounts WHERE id = ? AND owner_id = ?").bind(id, ownerId).run();
    if (!result.meta.changes) throw new Error("연결 계정을 찾을 수 없습니다.");
    return Response.json({ ok: true });
  } catch (error) { return apiError(error); }
}
