import { FastifyInstance } from 'fastify';
import {
    createWalkthrough,
    getWalkthroughs,
    getWalkthrough,
    getTodaysWalkthrough,
    completeWalkthrough,
    addReservoirCheck,
    addIrrigationCheck,
    addPlantHealthCheck,
} from '../controllers/walkthrough.controller';

export async function walkthroughRoutes(server: FastifyInstance) {
    // Auth middleware
    server.addHook('onRequest', async (request) => {
        try {
            await request.jwtVerify();
        } catch (err) {
            throw err;
        }
    });

    // Walkthrough CRUD
    server.post('/', createWalkthrough);
    server.get('/', getWalkthroughs);
    server.get('/today', getTodaysWalkthrough);  // Must come before /:id
    server.get('/:id', getWalkthrough);
    server.post('/:id/complete', completeWalkthrough);

    // Add checks to walkthrough
    server.post('/:id/reservoir-checks', addReservoirCheck);
    server.post('/:id/irrigation-checks', addIrrigationCheck);
    server.post('/:id/plant-health-checks', addPlantHealthCheck);
}

