# Confirmed Status Update Summary

## Overview
Added a new "confirmed" status to the addon_requests table and updated all related components in the system.

## Changes Made

### 1. Enum Update
**File:** `app/Enums/AddonRequest/Status.php`
- Added `CONFIRMED = 'confirmed'` case
- Added Chinese label: '已確認'
- Added English label: 'Confirmed'
- Added color: 'primary'
- Updated `canTransitionTo()` method:
  - `IN_PROGRESS` can now transition to `CONFIRMED`
  - `CONFIRMED` can transition to `COMPLETED` or `CANCELLED`

### 2. Database Migration
**File:** `database/migrations/2025_11_17_000004_add_confirmed_status_to_addon_requests_table.php`
- Created new migration to add 'confirmed' to the status enum column
- Supports both up and down migrations for rollback

### 3. Model Update
**File:** `app/Models/AddonRequest.php`
- Added `STATUS_CONFIRMED = 'confirmed'` constant
- Updated `getStatuses()` method to include confirmed
- Updated `getStatusLabelAttribute()` to handle confirmed status
- Updated `getIsOverdueAttribute()` to exclude confirmed from overdue checks

### 4. Service Update
**File:** `app/Services/AddonRequestService.php`
- Updated `getDashboardStats()` method to include `confirmed_requests` count
- Updated overdue requests calculation to exclude confirmed status

### 5. Controller Update
**File:** `app/Http/Controllers/Api/AddonRequestController.php`
- Updated overdue filter logic to exclude confirmed status from overdue calculations

### 6. Documentation Update
**File:** `ADDON_REQUEST_FRONTEND_DOCUMENTATION.md`
- Updated TypeScript interface to include 'confirmed' in status type union

## Status Workflow

The updated status workflow is:

```
PENDING → IN_PROGRESS → CONFIRMED → COMPLETED
    ↓           ↓            ↓
CANCELLED   CANCELLED    CANCELLED
    ↓           ↓
REJECTED    REJECTED
```

### Status Transitions

- **PENDING** can transition to:
  - IN_PROGRESS
  - CANCELLED
  - REJECTED

- **IN_PROGRESS** can transition to:
  - CONFIRMED (NEW)
  - COMPLETED
  - CANCELLED
  - REJECTED

- **CONFIRMED** can transition to:
  - COMPLETED
  - CANCELLED

- **COMPLETED** - Final state (no transitions)

- **CANCELLED** - Final state (no transitions)

- **REJECTED** can transition to:
  - PENDING (for resubmission)

## Active Status

The `isActive()` method considers these statuses as active:
- PENDING
- IN_PROGRESS
- CONFIRMED (NEW - still active)

Inactive (final) statuses:
- COMPLETED
- CANCELLED
- REJECTED

## API Changes

### Status Options Response
All endpoints returning `status_options` now include:
```json
{
  "value": "confirmed",
  "label": "已確認",
  "label_en": "Confirmed",
  "color": "primary"
}
```

### Dashboard Stats Response
The `/api/addon-requests/dashboard-stats` endpoint now includes:
```json
{
  "confirmed_requests": 5,
  ...
}
```

### Filtering
You can now filter requests by confirmed status:
```
GET /api/addon-requests?status=confirmed
```

## Migration Instructions

To apply this update to your database:

```bash
php artisan migrate
```

To rollback if needed:
```bash
php artisan migrate:rollback
```

## Testing Recommendations

1. **Status Transition Testing:**
   - Verify IN_PROGRESS → CONFIRMED transition works
   - Verify CONFIRMED → COMPLETED transition works
   - Verify CONFIRMED → CANCELLED transition works
   - Verify invalid transitions are blocked

2. **API Testing:**
   - Test status filter with confirmed value
   - Verify dashboard stats include confirmed_requests
   - Verify overdue filter excludes confirmed requests

3. **Frontend Testing:**
   - Update status badge UI to display confirmed status
   - Test status change dropdown includes confirmed option
   - Verify confirmed requests appear in appropriate lists

## Notes

- The "confirmed" status represents a state where the add-on request has been verified/confirmed by the department but not yet completed
- Confirmed requests are not considered overdue
- Confirmed requests are still considered "active" (in progress)
- The status uses "primary" color for UI display

