import { FastifyInstance } from 'fastify';
import {
    getCameras,
    getCameraById,
    getCameraStream,
    createCamera,
    updateCamera,
    deleteCamera,
    updateCameraStatus
} from '../controllers/cameras.controller';

export async function cameraRoutes(server: FastifyInstance) {
    // Auth required for all routes
    server.addHook('onRequest', async (request) => {
        try {
            await request.jwtVerify();
        } catch (err) {
            throw err;
        }
    });

    // CRUD Routes
    server.get('/', getCameras);
    server.get('/:id', getCameraById);
    server.get('/:id/stream', getCameraStream);
    server.post('/', createCamera);
    server.put('/:id', updateCamera);
    server.delete('/:id', deleteCamera);
    server.patch('/:id/status', updateCameraStatus);
}
