/**
 * Status Endpoint
 * GET /v1/status
 *
 * Returns API status and configuration
 */

module.exports = async (req, res, next, slmapi) => {
    try {
        const response = {
            error: false,
            message: 'API is operational',
            data: {
                name: slmapi.api_name,
                version: slmapi.api_version,
                status: 'operational',
                uptime: process.uptime(),
                environment: process.env.NODE_ENV || 'development',
                elasticsearch: {
                    server: slmapi.es_server,
                    index: slmapi.es_index
                },
                features: {
                    authentication: true,
                    rate_limiting: slmapi.rate_limit_enabled,
                    hot_reload: true
                },
                memory: {
                    rss: `${Math.round(process.memoryUsage().rss / 1024 / 1024)}MB`,
                    heapTotal: `${Math.round(process.memoryUsage().heapTotal / 1024 / 1024)}MB`,
                    heapUsed: `${Math.round(process.memoryUsage().heapUsed / 1024 / 1024)}MB`
                }
            },
            timestamp: slmapi.timestamp()
        };

        return res.status(200).json(response);

    } catch (error) {
        console.error('Error in status endpoint:', error);
        return res.status(500).json({
            error: true,
            message: 'Internal server error',
            timestamp: slmapi.timestamp()
        });
    }
};
