<?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();
$data = json_decode(file_get_contents('php://input'), true);

if (empty($data['category_id'])) {
    Response::error('category_id is required', 422);
}

$categoryId = (int)$data['category_id'];

/**
 * Check exists
 */
$stmt = $db->prepare("SELECT id FROM blog_categories WHERE id = :id");
$stmt->execute(['id' => $categoryId]);
if (!$stmt->fetch()) {
    Response::error('Category not found', 404);
}

/**
 * Deactivate
 */
$stmt = $db->prepare("
    UPDATE blog_categories
    SET status = 'InActive'
    WHERE id = :id
");
$stmt->execute(['id' => $categoryId]);

Response::success('Blog category deactivated successfully');
