<?php
require_once __DIR__ . '/../includes/api-helpers.php';
api_require_post();
if (api_is_spam()) api_json(true, 'You are subscribed to VIP Property Alerts.');

$name = api_str('name', 120);
$email = api_str('email', 160);
$phone = api_str('phone', 40);
$budgetMin = !empty($_POST['budget_min']) ? (float)$_POST['budget_min'] : null;
$budgetMax = !empty($_POST['budget_max']) ? (float)$_POST['budget_max'] : null;
$propertyType = api_str('property_type', 100);
$district = api_str('district', 100);

if ($name === '' || !api_valid_email($email)) {
    api_json(false, 'Please fill in your name and a valid email.');
}

$stmt = db()->prepare('INSERT INTO vip_alerts (name, email, phone, budget_min, budget_max, property_type, district) VALUES (?, ?, ?, ?, ?, ?, ?)');
$stmt->execute([$name, $email, $phone, $budgetMin, $budgetMax, $propertyType, $district]);

api_json(true, 'You are now subscribed to VIP Property Alerts — we will notify you the moment a matching listing goes live.');
