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

type GroupIdParams = { groupId: string };

export async function cancelRecurringGroupHandler(c: AppContext) {
  const { groupId } = c.req.valid('param' as never) as GroupIdParams;
  const user = c.get('user');

  try {
    const result = await cancelRecurringGroup(user.id, groupId);
    return c.json(result);
  } catch (error) {
    if (error instanceof AdminBookingServiceError) {
      return c.json({ message: error.message }, error.status);
    }
    throw error;
  }
}
