import { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
import { createTouchPoint, getTouchPoints, getRecentTouchPoints } from '../controllers/touch-points.controller';

export async function touchPointsRoutes(fastify: FastifyInstance) {
    const authenticate = async (request: FastifyRequest, reply: FastifyReply) => {
        try {
            await request.jwtVerify();
        } catch (err) {
            reply.send(err);
        }
    };

    fastify.post('/api/touch-points', { preHandler: [authenticate] }, createTouchPoint);
    interface GetRecentTouchPointsRequest {
        Querystring: {
            limit?: number;
        }
    }

    fastify.get<GetRecentTouchPointsRequest>('/api/touch-points', { preHandler: [authenticate] }, getRecentTouchPoints);

    interface GetTouchPointsRequest {
        Params: {
            batchId: string;
        }
    }
    fastify.get<GetTouchPointsRequest>('/api/batches/:batchId/touch-points', { preHandler: [authenticate] }, getTouchPoints);
}
