# Contact Page & Lead Management System Implementation Notes

This document provides a technical guide to the database schema, models, Filament resources, controllers, spam protection, and SEO/Schema structures developed for the **Kevron Suites and Apartments Contact Page** at `/contact`.

---

## 1. Database Schema & Dynamic Data Lookups

To avoid hardcoded URLs or phone numbers, we introduced 8 new sequence-compliant database tables:
1. **`contact_settings`**: Holds dynamic variables for telephone, email, WhatsApp, and coordinates (`contact_phone`, `contact_email`, `contact_whatsapp`, `contact_address`).
2. **`map_settings`**: Holds dynamic embedding links (`map_embed_url`) and coordinate pointers (`map_directions_url`).
3. **`support_hours`**: Timed operational hours grouped by channels (Booking, WhatsApp, Corporate Stays).
4. **`social_links`**: Configuration links for active corporate social profiles (Instagram, Facebook, TikTok, LinkedIn).
5. **`enquiry_types`**: Configurable options for the general enquiry categories dropdown.
6. **`contact_enquiries`**: Persistent storage for all general submissions.
7. **`booking_enquiries`**: Leads for en-suite suite check-in availability dates.
8. **`spam_logs`**: Logs rate-limiting or honeypot trap events for security audit trails.

---

## 2. Dynamic AJAX Submissions & Spam Protection

Public forms are integrated with Alpine.js front-end controllers to switch tabs seamlessly with zero page refreshes.

### Honeypot Anti-Spam Controls
All forms contain a hidden input field styled to be invisible to users (`confirm_email`).
* If a bot submits with this field populated:
  - The request logs to `spam_logs` (including IP, form, and payload).
  - Returns a successful fake JSON response (`success => true`) to confuse bots without saving the fake lead to corporate databases.

### Throttling & Double-Submit Prevention
A robust, built-in IP rate limiter intercepts requests, validating if the incoming IP has submitted a lead on the current form in the last 15 seconds. If so, it aborts with a `429 Too Many Requests` code.

---

## 3. Dynamic Notifications

Upon successful lead entry, a user confirmation and an admin email/SMS alert are scheduled via the `BookingNotification` model queue system:
* **General Enquiries**: `contact_enquiry_received` (User), `new_contact_enquiry` (Admin).
* **Availability Enquiries**: `booking_enquiry_received` (User), `new_booking_enquiry` (Admin).
* **Corporate B2B Stays**: `corporate_enquiry_received` (User), `new_corporate_enquiry` (Admin).

---

## 4. Filament Admin Dashboard CRUD Manager

8 dynamic Filament Resources are added to the admin dashboard under the navigation groups **Contact & Leads Management** and **Customer Enquiries & Leads**:
1. `ContactSettingResource`: Manage telephone numbers, emails, and address strings.
2. `MapSettingResource`: Coordinate embeds and map details.
3. `SupportHourResource`: Manage timed operational support schedules.
4. `SocialLinkResource`: Manage active corporate branding platform paths.
5. `EnquiryTypeResource`: CRUD enquiry options.
6. `ContactEnquiryResource`: General enquiries and status tracking.
7. `BookingEnquiryResource`: Availability checks and status badges.
8. `SpamLogResource`: View and audit rate limits and honeypots.

---

## 5. Structured Data & SEO Requirements

Automatically loads crawlable SEO titles, descriptions, and breadcrumbs.
Injects dynamic polymorphic ContactPage JSON-LD schemas incorporating:
* LodgingBusiness coordinates.
* PostalAddress.
* FAQPage details.

---

## 6. Verification and Testing

### Automated PHPUnit Suite
The complete lead-generation pipeline is verified inside `tests/Feature/ContactPageTest.php`:
* Page loads with 200 OK.
* Nav header `KEVRON` and footer address are present.
* Dynamic settings lookups and support hour tables render.
* Form submissions validate, trap spam bots, log leads, and queue notification jobs.

Run tests:
```bash
php artisan test --filter=ContactPageTest
```
