<?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['tag_id'])) {
    Response::error('tag_id is required', 422);
}

$tagId = (int)$data['tag_id'];

/**
 * Exists check
 */
$stmt = $db->prepare("SELECT id FROM blog_tags WHERE id = :id");
$stmt->execute(['id' => $tagId]);
if (!$stmt->fetch()) {
    Response::error('Tag not found', 404);
}

/**
 * Activate
 */
$stmt = $db->prepare("
    UPDATE blog_tags
    SET status = 'Active'
    WHERE id = :id
");
$stmt->execute(['id' => $tagId]);

Response::success('Blog tag activated successfully');
