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

/* ================= INPUT ================= */
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;

if ($id <= 0) {
    Response::error('Invalid category ID');
    exit;
}

/* ================= FETCH ================= */
$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 id = :id
    LIMIT 1
");

$stmt->execute(['id' => $id]);
$category = $stmt->fetch(PDO::FETCH_ASSOC);

if (!$category) {
    Response::error('Category not found');
    exit;
}

/* ================= RESPONSE ================= */
Response::success('Retail category fetched', $category);
