import { AdminBookingServiceError } from '@/modules/admin-booking/services/admin-booking.service';
import { listRecurringGroups } from '@/modules/admin-booking/services/admin-recurring-booking.service';
import type { AppContext } from '@/types/hono';

type ComplexIdParams = { complexId: string };

export async function listRecurringGroupsHandler(c: AppContext) {
  const { complexId } = c.req.valid('param' as never) as ComplexIdParams;

  try {
    const groups = await listRecurringGroups(complexId);
    return c.json({ groups });
  } catch (error) {
    if (error instanceof AdminBookingServiceError) {
      return c.json({ message: error.message }, error.status);
    }
    throw error;
  }
}
