/**
 * POST /api/login-status/[id]/check — run one source's check, update cache.
 */
import { NextResponse } from 'next/server';
import { listSources, checkSource } from '@/lib/auth/login-status';

export async function POST(_req: Request, { params }: { params: Promise<{ id: string }> }) {
  const { id } = await params;
  const source = listSources().find((s) => s.id === id);
  if (!source) {
    return NextResponse.json({ ok: false, error: `unknown source: ${id}` }, { status: 404 });
  }
  try {
    const result = await checkSource(source);
    return NextResponse.json({ source, result });
  } catch (e) {
    return NextResponse.json(
      { ok: false, error: `check failed: ${(e as Error).message}` },
      { status: 500 },
    );
  }
}
