# ═══════════════════════════════════════════════════════════════
# PHASE 8: FACILITIES, BOOKINGS & EVENTS MODULE
# Module directory: /modules/facilities/
# ═══════════════════════════════════════════════════════════════
# READ THE MASTER PROMPT FIRST.

## YOUR TABLES
facility_types, facilities, facility_time_slots, facility_slot_overrides,
facility_access_schedules, facility_amenities, facility_bookings,
facility_booking_participants, facility_maintenance, club_events,
club_event_registrations, swimming_pools, swimming_pool_readings,
parking_zones, parking_permits, parking_log

## PAGES TO BUILD

### 1. Facilities Listing (`GET /facilities`)
- Card grid or DataTable of all facilities
- Status indicators (active, maintenance, closed)
- Quick stats: total, active, under maintenance

### 2. Facility CRUD (`GET /facilities/create`, etc.)
- Full form with all facility fields
- Amenities management
- Time slots configuration (weekly schedule)
- Slot overrides (holidays, special events)
- Access schedule per membership type
- Photo upload

### 3. Facility Types Management
- CRUD for facility_types

### 4. Booking Calendar (`GET /facilities/{id}/bookings`)
- Weekly calendar view showing time slots and bookings
- Color-coded by booking type/status
- Click-to-book on empty slots
- Booking detail modal on click

### 5. Create Booking (`POST /facilities/bookings`)
- Member lookup, facility, date, time slot selection
- Participant management
- Check availability (call `sp_check_booking_availability`)
- Fee calculation
- Validation: advance booking days, membership type access

### 6. Booking Management (`GET /bookings`)
- DataTable of all bookings
- Filters: Facility, Status, Date Range
- Actions: Confirm, Check-in, Complete, Cancel
- Cancellation with fee calculation

### 7. Facility Maintenance (`GET /facilities/{id}/maintenance`)
- CRUD for facility_maintenance records
- Schedule upcoming maintenance
- Track costs

### 8. Events (`GET /events`)
- DataTable: Code, Title, Type, Date, Venue, Attendees, Status
- Create/Edit event with full details
- Registration management:
  - Member registration
  - Guest allowance
  - Fee collection
  - Attendee check-in
- Event types: social, sport, cultural, etc.

### 9. Swimming Pools (`GET /facilities/pools`)
- Pool configuration (swimming_pools)
- Water quality readings entry (swimming_pool_readings)
- Compliance tracking
- Reading history chart (pH, chlorine, temperature over time)

### 10. Parking (`GET /facilities/parking`)
- Zones management (parking_zones)
- Permit issuance (parking_permits)
- Parking log view
- Permit status management

## BUSINESS LOGIC
- Booking conflict detection via sp_check_booking_availability
- Slot overrides block bookings on closed days
- Maintenance records set facility status
- Event registration respects max_attendees
- Pool readings flag non-compliance

## DASHBOARD WIDGETS
1. **Today's Bookings** — Count by facility
2. **Upcoming Events** — Next 3 events
3. **Facility Status** — Active/Maintenance/Closed counts

## PERMISSIONS
facilities.view, facilities.manage,
bookings.view, bookings.create, bookings.manage,
events.view, events.manage