<?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();

$status = $_GET['status'] ?? null;
$where  = '';
$params = [];

if ($status) {
    $where = "WHERE status = :status";
    $params['status'] = $status;
}

$stmt = $db->prepare("
    SELECT
        id,
        category_name,
        slug,
        short_description,
        description,
        image_path,
        image_alt,
        meta_title,
        meta_description,
        meta_keywords,
        ai_summary,
        status,
        created_at,
        updated_at
    FROM retail_categories
    $where
    ORDER BY category_name ASC
");

$stmt->execute($params);

Response::success('Retail categories fetched', $stmt->fetchAll());
