<?php
declare(strict_types=1);

require_once __DIR__ . '/../../security/auth_guard.php';
require_once __DIR__ . '/../../security/csrf_guard.php';
require_once __DIR__ . '/../../config/database.php';
require_once __DIR__ . '/../../core/Response.php';

$data = json_decode(file_get_contents('php://input'), true);

if (empty($data['image_id']) || empty($data['status'])) {
    Response::error('image_id and status are required', 422);
}

if (!in_array($data['status'], ['Active', 'Inactive'], true)) {
    Response::error('Invalid status', 422);
}

$db = Database::getInstance();

$stmt = $db->prepare("
    UPDATE dealer_images
    SET status = :status
    WHERE id = :id
");
$stmt->execute([
    'status' => $data['status'],
    'id'     => (int)$data['image_id']
]);

Response::success('Image status updated');
