import { cancelPublicBookingHandler } from '@/modules/public-booking/handlers/cancel-public-booking.handler';
import { createPublicBookingHandler } from '@/modules/public-booking/handlers/create-public-booking.handler';
import { getPublicBookingConfirmationHandler } from '@/modules/public-booking/handlers/get-public-booking-confirmation.handler';
import { listPublicAvailabilityHandler } from '@/modules/public-booking/handlers/list-public-availability.handler';
import type { AppEnv } from '@/types/hono';
import { zValidator } from '@hono/zod-validator';
import {
  cancelPublicBookingSchema,
  createPublicBookingSchema,
  publicAvailabilityQuerySchema,
} from '@repo/api-contract';
import { Hono } from 'hono';
import { z } from 'zod';

export const publicBookingRoutes = new Hono<AppEnv>();
const complexSlugParamsSchema = z.object({ complexSlug: z.string().trim().min(1) });
const confirmationParamsSchema = z.object({
  complexSlug: z.string().trim().min(1),
  bookingCode: z.string().trim().min(6).max(8),
});

publicBookingRoutes.get(
  '/complex/:complexSlug/availability',
  zValidator('param', complexSlugParamsSchema),
  zValidator('query', publicAvailabilityQuerySchema),
  listPublicAvailabilityHandler
);

publicBookingRoutes.post(
  '/complex/:complexSlug',
  zValidator('param', complexSlugParamsSchema),
  zValidator('json', createPublicBookingSchema),
  createPublicBookingHandler
);

publicBookingRoutes.get(
  '/complex/:complexSlug/confirmation/:bookingCode',
  zValidator('param', confirmationParamsSchema),
  getPublicBookingConfirmationHandler
);

publicBookingRoutes.post(
  '/complex/:complexSlug/cancel',
  zValidator('param', complexSlugParamsSchema),
  zValidator('json', cancelPublicBookingSchema),
  cancelPublicBookingHandler
);
