# Phase 10: Cross-cutting Concerns

## Objective
Implement notifications, Pusher real-time events, translations, cleanup jobs, and observer-based side effects.

---

## Tasks

### 10.1 Notifications

**Directory:** `app/Notifications/App/`

#### CustomerHotelReservationConfirmedNotification
Sent to guest when reservation is confirmed.
Channels: `expo` (push), `sendinblue_email`, `database`

#### CustomerHotelCheckInReminderNotification
Sent to guest 24h before check-in date.
Channels: `expo` (push), `sendinblue_email`

#### CustomerHotelCheckOutReminderNotification
Sent to guest on check-out day morning.
Channels: `expo` (push)

#### EmployeeNewHotelReservationNotification
Sent to hotel managers when a new reservation is created.
Channels: `expo` (push), `database`

#### CustomerHotelReservationCancelledNotification
Sent to guest when reservation is cancelled.
Channels: `sendinblue_email`, `database`

### 10.2 Observer

**File:** `app/Observers/HotelReservationObserver.php`

Register in `EventServiceProvider`.

```php
public function created(HotelReservation $reservation): void
{
    // Notify hotel managers of new reservation
    // Dispatch channel availability sync if channels configured
}

public function updated(HotelReservation $reservation): void
{
    // On status change to CONFIRMED: notify guest
    // On status change to CANCELLED: notify guest + free rooms
    // On status change to CHECKED_OUT: dispatch housekeeping
    // Dispatch channel availability sync on any status change
}
```

### 10.3 Pusher Real-time Events

**File:** `app/Events/Hotel/HotelReservationUpdated.php`

Broadcast on `place.{placeId}` channel when:
- New reservation created
- Reservation status changed
- Room status changed

This allows the Filament dashboard to refresh in real-time.

**File:** `app/Events/Hotel/HotelRoomStatusChanged.php`

Broadcast on `place.{placeId}` channel for housekeeping dashboard updates.

### 10.4 Scheduled Commands

#### CheckInReminderCommand
**File:** `app/Console/Commands/SendHotelCheckInRemindersCommand.php`

```bash
php artisan hotel:send-checkin-reminders
```

Scheduled daily at 10:00 AM (in hotel timezone). Sends reminders for tomorrow's arrivals.

#### CheckOutReminderCommand
**File:** `app/Console/Commands/SendHotelCheckOutRemindersCommand.php`

```bash
php artisan hotel:send-checkout-reminders
```

Scheduled daily at 8:00 AM. Sends reminders for today's departures.

#### AutoNoShowCommand
**File:** `app/Console/Commands/AutoNoShowHotelReservationsCommand.php`

```bash
php artisan hotel:auto-no-show
```

Scheduled daily at 11:59 PM. Marks CONFIRMED reservations with past check_in date (and not checked in) as NO_SHOW.

#### StaleReservationCleanupCommand
**File:** `app/Console/Commands/CleanupStaleHotelReservationsCommand.php`

```bash
php artisan hotel:cleanup-stale-reservations
```

Scheduled daily. Cancels PENDING reservations older than 48h without payment.

### 10.5 Translations

Ensure all translatable fields are properly configured:

| Model | Translatable Fields |
|---|---|
| `Hotel` | `name`, `description` |
| `HotelRoomType` | `name`, `description` |
| `HotelSeasonalRate` | `name` |
| `HotelExtra` | `name`, `description` |

Add translation keys for:
- Enum labels (all hotel enums)
- Notification messages
- Email templates

### 10.6 Tests

**File:** `tests/Feature/Controllers/HotelManager/CrossCuttingTest.php`

- [ ] Guest receives notification on reservation confirmation
- [ ] Guest receives notification on reservation cancellation
- [ ] Hotel managers receive notification on new reservation
- [ ] Observer dispatches channel sync on status change
- [ ] Pusher events broadcast correctly
- [ ] Check-in reminder command sends to correct guests
- [ ] Auto no-show marks correct reservations
- [ ] Stale reservation cleanup cancels old pending reservations
- [ ] Translations work for all translatable models

---

## Files Created/Modified

| Action | File |
|---|---|
| Create | `app/Notifications/App/CustomerHotelReservationConfirmedNotification.php` |
| Create | `app/Notifications/App/CustomerHotelCheckInReminderNotification.php` |
| Create | `app/Notifications/App/CustomerHotelCheckOutReminderNotification.php` |
| Create | `app/Notifications/App/EmployeeNewHotelReservationNotification.php` |
| Create | `app/Notifications/App/CustomerHotelReservationCancelledNotification.php` |
| Create | `app/Observers/HotelReservationObserver.php` |
| Create | `app/Events/Hotel/HotelReservationUpdated.php` |
| Create | `app/Events/Hotel/HotelRoomStatusChanged.php` |
| Create | `app/Console/Commands/SendHotelCheckInRemindersCommand.php` |
| Create | `app/Console/Commands/SendHotelCheckOutRemindersCommand.php` |
| Create | `app/Console/Commands/AutoNoShowHotelReservationsCommand.php` |
| Create | `app/Console/Commands/CleanupStaleHotelReservationsCommand.php` |
| Modify | `app/Providers/EventServiceProvider.php` — register observer + listeners |
| Modify | `app/Console/Kernel.php` — schedule commands |
| Create | `tests/Feature/Controllers/HotelManager/CrossCuttingTest.php` |

---

## Acceptance Criteria

- [ ] All 5 notification classes created
- [ ] Observer triggers correct notifications and side effects
- [ ] Pusher events broadcast on reservation/room changes
- [ ] All 4 scheduled commands registered and functional
- [ ] Auto no-show correctly identifies past reservations
- [ ] Stale cleanup cancels old PENDING reservations
- [ ] Translations work for hotel models
- [ ] All tests pass
- [ ] Pint + PHPStan pass on new/modified files
