import { requireAuth } from '@/middlewares/require-auth.middleware';
import { cancelRecurringGroupHandler } from '@/modules/admin-booking/handlers/cancel-recurring-group.handler';
import { createAdminBookingHandler } from '@/modules/admin-booking/handlers/create-admin-booking.handler';
import { createAdminRecurringBookingHandler } from '@/modules/admin-booking/handlers/create-admin-recurring-booking.handler';
import { listAdminBookingsHandler } from '@/modules/admin-booking/handlers/list-admin-bookings.handler';
import { listRecurringGroupsHandler } from '@/modules/admin-booking/handlers/list-recurring-groups.handler';
import { updateAdminBookingStatusHandler } from '@/modules/admin-booking/handlers/update-admin-booking-status.handler';
import { updateRecurringGroupHandler } from '@/modules/admin-booking/handlers/update-recurring-group.handler';
import type { AppEnv } from '@/types/hono';
import { zValidator } from '@hono/zod-validator';
import {
  createAdminBookingSchema,
  createRecurringBookingSchema,
  listAdminBookingsQuerySchema,
  updateAdminBookingStatusSchema,
  updateRecurringGroupSchema,
} from '@repo/api-contract';
import { Hono } from 'hono';
import { z } from 'zod';

export const adminBookingRoutes = new Hono<AppEnv>();
const complexIdParamsSchema = z.object({ complexId: z.uuid() });
const bookingIdParamsSchema = z.object({ id: z.uuid() });
const groupIdParamsSchema = z.object({ groupId: z.uuid() });

adminBookingRoutes.use('*', requireAuth);

adminBookingRoutes.get(
  '/complex/:complexId',
  zValidator('param', complexIdParamsSchema),
  zValidator('query', listAdminBookingsQuerySchema),
  listAdminBookingsHandler
);

adminBookingRoutes.post(
  '/complex/:complexId',
  zValidator('param', complexIdParamsSchema),
  zValidator('json', createAdminBookingSchema),
  createAdminBookingHandler
);

adminBookingRoutes.post(
  '/complex/:complexId/recurring',
  zValidator('param', complexIdParamsSchema),
  zValidator('json', createRecurringBookingSchema),
  createAdminRecurringBookingHandler
);

adminBookingRoutes.post(
  '/recurring/:groupId/cancel',
  zValidator('param', groupIdParamsSchema),
  cancelRecurringGroupHandler
);

adminBookingRoutes.get(
  '/complex/:complexId/recurring',
  zValidator('param', complexIdParamsSchema),
  listRecurringGroupsHandler
);

adminBookingRoutes.patch(
  '/recurring/:groupId',
  zValidator('param', groupIdParamsSchema),
  zValidator('json', updateRecurringGroupSchema),
  updateRecurringGroupHandler
);

adminBookingRoutes.patch(
  '/:id/status',
  zValidator('param', bookingIdParamsSchema),
  zValidator('json', updateAdminBookingStatusSchema),
  updateAdminBookingStatusHandler
);
