<?php
declare(strict_types=1);

require_once __DIR__ . '/../../../security/auth_guard.php';
require_once __DIR__ . '/../../../config/database.php';
require_once __DIR__ . '/../../../core/Response.php';

$db = Database::getInstance();

$context = $_GET['context'] ?? 'backend'; // backend | frontend

$sql = "
    SELECT id, name, slug, status, created_at
    FROM faq_categories
";

if ($context === 'frontend') {
    $sql .= " WHERE status = 'Active'";
}

$sql .= " ORDER BY name ASC";

$stmt = $db->query($sql);
$categories = $stmt->fetchAll();

Response::success('FAQ categories fetched successfully', $categories);
