# Phase 7: Housekeeping

## Objective
Implement room housekeeping status management, task lists, auto-transitions, and history tracking.

---

## Tasks

### 7.1 Filament — Housekeeping Overview

**File:** `app/Filament/Resources/HotelResource/Pages/HotelHousekeeping.php`

A custom page on HotelResource showing:
- Grid/table of all rooms with current housekeeping status
- Color-coded badges (DIRTY=red, IN_PROGRESS=yellow, CLEAN=green, INSPECTED=blue, OUT_OF_ORDER=gray)
- Quick-action buttons to change status
- Filter by floor, room type, status

### 7.2 Actions

#### UpdateHousekeepingStatusAction
**File:** `app/Actions/HotelManager/UpdateHousekeepingStatusAction.php`

```php
final class UpdateHousekeepingStatusAction
{
    public function __invoke(
        HotelRoom $room,
        HotelHousekeepingStatus $newStatus,
        ?Employee $employee = null,
        ?string $notes = null,
    ): HotelHousekeepingLog;
}
```

Logic:
1. Record current status as from_status
2. Update room.housekeeping_status
3. Create HotelHousekeepingLog entry
4. If transitioning to IN_PROGRESS, set started_at
5. If transitioning to CLEAN or INSPECTED, set completed_at
6. Return log entry

Valid transitions:
- DIRTY → IN_PROGRESS, OUT_OF_ORDER
- IN_PROGRESS → CLEAN, DIRTY (reset), OUT_OF_ORDER
- CLEAN → INSPECTED, DIRTY, OUT_OF_ORDER
- INSPECTED → DIRTY, OUT_OF_ORDER
- OUT_OF_ORDER → DIRTY

### 7.3 API — Housekeeping Endpoints

#### HousekeepingDashboardController
```
GET /v1/places/{place}/hotels/{hotel}/housekeeping
```
Returns all rooms grouped by housekeeping status with counts:
```json
{
    "summary": {
        "clean": 45,
        "dirty": 12,
        "in_progress": 3,
        "inspected": 30,
        "out_of_order": 2
    },
    "rooms": [...rooms with status, floor, room_type, current_guest...]
}
```

Filterable by floor, room_type_id, housekeeping_status.

#### UpdateHousekeepingStatusController
```
PATCH /v1/places/{place}/hotels/{hotel}/rooms/{room}/housekeeping
Body: status, notes (optional)
```

#### ListHousekeepingTasksController
```
GET /v1/places/{place}/hotels/{hotel}/housekeeping/tasks
```
Returns rooms needing attention, prioritized by:
1. Rooms with upcoming arrivals today (highest priority)
2. Rooms with DIRTY status
3. Rooms with IN_PROGRESS status

Response includes:
- Room info + floor + room type
- Priority level (HIGH, MEDIUM, LOW)
- Expected arrival time (if applicable)
- Time since checkout (if applicable)

### 7.4 Auto-transitions

Already implemented in Phase 5:
- On checkout: room housekeeping_status → DIRTY (via CheckOutGuestAction)
- Housekeeping log created automatically

Additional auto-transition (optional, via scheduled command):
- Rooms CLEAN for > 24h without check-in → can be flagged for re-inspection

### 7.5 Resources

- `HotelHousekeepingDashboardResource` — Dashboard summary + rooms
- `HotelHousekeepingTaskResource` — Task with priority info

### 7.6 Form Requests

- `UpdateHousekeepingRequest` — status (enum), notes (optional)

### 7.7 Tests

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

- [ ] Housekeeping dashboard returns correct summary counts
- [ ] Manager can update housekeeping status
- [ ] Status transition creates log entry
- [ ] Invalid transitions are rejected
- [ ] Tasks endpoint returns rooms sorted by priority
- [ ] Rooms with upcoming arrivals are highest priority
- [ ] Checkout auto-sets rooms to DIRTY
- [ ] IN_PROGRESS sets started_at on log
- [ ] CLEAN/INSPECTED sets completed_at on log

---

## Acceptance Criteria

- [ ] Filament housekeeping page with color-coded grid
- [ ] All 3 API endpoints functional
- [ ] Status transitions validated correctly
- [ ] Housekeeping logs created on every transition
- [ ] Task prioritization based on arrivals
- [ ] Auto-transition on checkout works
- [ ] All Swagger annotations present
- [ ] All tests pass
- [ ] Pint + PHPStan pass on new/modified files
