import { db } from '@/lib/prisma';
import type { AppContext } from '@/types/hono';

export async function listPlansAdminHandler(c: AppContext) {
  const plans = await db.plan.findMany({
    orderBy: { price: 'asc' },
    include: {
      _count: {
        select: { complexes: true },
      },
    },
  });

  return c.json(
    plans.map((plan) => ({
      code: plan.code,
      name: plan.name,
      price: Number(plan.price),
      rules: plan.rules,
      lastUpdatedAt: plan.lastUpdatedAt.toISOString(),
      complexCount: plan._count.complexes,
    }))
  );
}
