<?php
/**
 * Rig N Dig - Mobile API v1 / FAQ
 */
header('Content-Type: application/json');
require_once '../../config/config.php';
require_once '../../includes/functions.php';
require_once 'api_helper.php';

try {
    $faqs = Database::fetchAll("SELECT id, question, answer, category FROM faqs WHERE is_active = 1 ORDER BY sort_order ASC, id ASC");
    
    // Group by category
    $grouped = [];
    foreach ($faqs as $f) {
        $cat = $f['category'] ?: 'General';
        if (!isset($grouped[$cat])) $grouped[$cat] = [];
        $grouped[$cat][] = $f;
    }

    apiResponse(true, 'FAQs loaded', [
        'total' => count($faqs),
        'categories' => $grouped
    ]);
} catch (Exception $e) {
    apiResponse(false, 'Failed to load FAQs');
}
