<?php
require_once __DIR__ . '/../includes/api-helpers.php';
api_require_post();
if (api_is_spam()) api_json(true, 'Thank you! Your property details have been received.');

$name = api_str('name', 120);
$email = api_str('email', 160);
$phone = api_str('phone', 40);
$propertyType = api_str('property_type', 100);
$status = api_str('status', 20);
$address = api_str('address', 300);
$askingPrice = api_str('asking_price', 60);
$description = api_str('description', 2000);

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

$message = "Listing type: $status\nProperty type: $propertyType\nAddress: $address\nAsking price: $askingPrice\nDescription: $description";

$stmt = db()->prepare('INSERT INTO leads (type, name, email, phone, message) VALUES (?, ?, ?, ?, ?)');
$stmt->execute(['list_property', $name, $email, $phone, $message]);

api_json(true, 'Thank you! One of our advisors will contact you within 24 hours to schedule a site visit.');
