<?php
namespace Peak;

class Router {
    public static function dispatch(string $method, string $resource, ?string $id): void {
        try {
            switch ($resource) {
                case 'auth': Auth::handleRequest($method, $id); break;
                case 'settings': Settings::handleRequest($method, $id); break;
                case 'profile': Profile::handleRequest($method); break;
                case 'activity': Activity::handleRequest($method); break;
                case 'workflows': WorkflowManager::handleRequest($method, $id); break;
                case 'me': Auth::handleRequest($method, 'me'); break;
                case 'admin-tokens': Auth::handleAdminTokens(); break;
                case 'generate-image': ImageGenerator::handleRequest(); break;
                case 'generate-video': VideoGenerator::handleRequest(); break;
                case 'chat': ChatAI::handleRequest(); break;
                case 'migrate': Migration::renderUI(); break;
                default: Response::error('Not found', 404);
            }
        } catch (\PDOException $e) {
            Response::error('Database connection failed: ' . $e->getMessage(), 503);
        } catch (\Throwable $e) {
            Response::error('Server error: ' . $e->getMessage(), 500);
        }
    }
}
