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

export async function listPlansHandler(c: AppContext) {
  const plans = await db.plan.findMany({
    select: {
      code: true,
      name: true,
      price: true,
    },
    orderBy: {
      price: 'asc',
    },
  });

  return c.json(
    plans.map((plan) => ({
      code: plan.code,
      name: plan.name,
      price: Number(plan.price),
    }))
  );
}
