<?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['faq_id']) || !filter_var($data['faq_id'], FILTER_VALIDATE_INT)) {
    Response::error('Valid faq_id is required', 422);
}

$faqId = (int)$data['faq_id'];

/**
 * Check FAQ exists
 */
$stmt = $db->prepare("SELECT id FROM faqs WHERE id = :id");
$stmt->execute(['id' => $faqId]);

if (!$stmt->fetch()) {
    Response::error('FAQ not found', 404);
}

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

Response::success('FAQ deactivated successfully');
