# TASK IMPLEMENTATION — WS-003

## Workspace Phase Evaluation

You are implementing the final implementation task of Sprint 3.

Current completed tasks:

* Sprint 0 ✅
* Sprint 1 ✅
* Sprint 2 ✅
* Database Foundation ✅
* S3-002 Security Hardening ✅
* S3-003 WorkspaceMiddleware ✅
* WS-001 Workspace Provisioning ✅
* WS-002 Workspace Setup Checklist ✅

Implement ONLY Workspace Phase Evaluation.

Do not begin Sprint 3 Architecture Review.

---

# Mandatory Reading

Read:

* AI.md v1.1
* SPRINT3_PLANNING.md
* SPRINT3_EXECUTION_GUIDE.md
* WS-001 implementation memories
* WS-002 implementation memory

If documentation conflicts exist:

STOP.

Report.

Wait.

---

# Objective

Implement the Workspace lifecycle evaluator.

Business logic belongs exclusively inside WorkspaceService.

Database access belongs exclusively inside WorkspaceModel.

---

# Files Allowed

## Modified Files

```text
app/modules/Workspace/WorkspaceService.php

app/modules/Workspace/WorkspaceModel.php
```

No new files.

No other files may be modified.

---

# Lifecycle Rules

Implement:

WorkspaceService::evaluatePhase(workspaceId)

The evaluation must determine the current workspace phase.

Possible phases:

* provisioned
* setup
* active
* live
* post_event
* archived
* purged

---

# Evaluation Rules

Evaluate only from documented business rules.

At minimum:

If wedding_date is in the future:

* setup
* active

If wedding_date is today:

* live

If wedding_date has passed:

* post_event

Archived and Purged states must remain terminal.

Never automatically revive archived or purged workspaces.

---

# Persistence

If phase changes:

* update workspaces.phase
* write audit_logs entry

If phase remains unchanged:

Do nothing.

No unnecessary UPDATE.

---

# Service Responsibilities

WorkspaceService:

* evaluate target phase
* compare with current phase
* request persistence through WorkspaceModel
* write audit log
* return evaluation result

No SQL.

No HTML.

No presentation.

---

# Model Responsibilities

WorkspaceModel:

* retrieve workspace information
* retrieve wedding_date
* update phase
* write audit log

Prepared statements only.

No business logic.

No transactions.

---

# Security

Verify:

* parameterized SQL
* workspace isolation
* audit log excludes secrets
* archived workspaces remain inaccessible
* purged workspaces remain inaccessible

---

# Constraints

Do NOT:

* modify WorkspaceMiddleware
* modify Controller
* modify Validator
* modify routes
* modify checklist
* modify provisioning
* modify app/core/*
* modify Router
* modify BaseController
* modify MiddlewarePipeline
* modify database schema
* modify authentication
* perform git operations

---

# Verification

Run:

php -l

Verify:

* every phase transition
* no transition loops
* archived remains archived
* purged remains purged
* audit log generation
* no unnecessary database updates

---

# Acceptance Criteria

PASS only if:

* evaluatePhase() implemented.
* All lifecycle phases supported.
* Archived/Purged remain terminal.
* Audit log generated only on change.
* No SQL outside WorkspaceModel.
* No business logic outside WorkspaceService.
* Parameterized queries only.
* PHP syntax passes.
* Scope respected.

---

# Output

Provide:

1. Files modified.
2. Lifecycle workflow.
3. Phase transition rules.
4. Audit workflow.
5. Security verification.
6. Acceptance checklist.
7. PHP syntax results.
8. Confirmation Sprint 3 Architecture Review was NOT started.

Stop after the implementation report.

Wait for Human Approval.
