<?php
require_once __DIR__ . '/../controllers/RodalController.php';

function handleRodalRoutes($path, $method, $db) {
    $controller = new RodalController($db);
    
    switch (true) {
        // GET /api/projects/{projectId}/rodales - Obtener rodales por proyecto
        case preg_match('/^projects\/(\d+)\/rodales$/', $path, $matches) && $method === 'GET':
            return $controller->getByProject($matches[1]);
            
        // POST /api/projects/{projectId}/rodales - Crear nuevo rodal
        case preg_match('/^projects\/(\d+)\/rodales$/', $path, $matches) && $method === 'POST':
            return $controller->store($matches[1]);
            
        // GET /api/rodales/{id} - Obtener rodal específico
        case preg_match('/^rodales\/(\d+)$/', $path, $matches) && $method === 'GET':
            return $controller->show($matches[1]);
            
        // PUT /api/rodales/{id} - Actualizar rodal
        case preg_match('/^rodales\/(\d+)$/', $path, $matches) && $method === 'PUT':
            return $controller->update($matches[1]);
            
        // DELETE /api/rodales/{id} - Eliminar rodal
        case preg_match('/^rodales\/(\d+)$/', $path, $matches) && $method === 'DELETE':
            return $controller->destroy($matches[1]);
            
        // GET /api/rodales/{id}/field-data - Obtener datos de campo por rodal
        case preg_match('/^rodales\/(\d+)\/field-data$/', $path, $matches) && $method === 'GET':
            return $controller->getFieldData($matches[1]);
            
        // GET /api/rodales/{id}/calculations - Obtener cálculos forestales del rodal
        case preg_match('/^rodales\/(\d+)\/calculations$/', $path, $matches) && $method === 'GET':
            return $controller->getCalculations($matches[1]);
    }
    
    return null;
}
?>