import { requireAuth } from '@/middlewares/require-auth.middleware';
import { createCourtHandler } from '@/modules/court/handlers/create-court.handler';
import { listCourtsByComplexHandler } from '@/modules/court/handlers/list-courts-by-complex.handler';
import { updateCourtHandler } from '@/modules/court/handlers/update-court.handler';
import type { AppEnv } from '@/types/hono';
import { zValidator } from '@hono/zod-validator';
import { createCourtSchema, updateCourtSchema } from '@repo/api-contract';
import { Hono } from 'hono';
import { z } from 'zod';

export const courtRoutes = new Hono<AppEnv>();
const complexIdParamsSchema = z.object({ complexId: z.uuid() });
const courtIdParamsSchema = z.object({ id: z.uuid() });

courtRoutes.use('*', requireAuth);

courtRoutes.get(
  '/complex/:complexId',
  zValidator('param', complexIdParamsSchema),
  listCourtsByComplexHandler
);
courtRoutes.post(
  '/complex/:complexId',
  zValidator('param', complexIdParamsSchema),
  zValidator('json', createCourtSchema),
  createCourtHandler
);
courtRoutes.patch(
  '/:id',
  zValidator('param', courtIdParamsSchema),
  zValidator('json', updateCourtSchema),
  updateCourtHandler
);
