# Tasks

## 1. Prerequisite and schema

- [x] 1.1 Verify establish-core-api-architecture is implemented, including shared DTOs and frontend compatibility; record passing baseline contract checks before building on its helpers.
- [x] 1.2 Produce a read-only migration preflight for duplicate scoped names, multiple WOs per report, inconsistent hierarchy, existing remote photo URLs, and legacy reviewed reports; verify it reports conflicts without changing data and document remediation requirements.
- [x] 1.3 Add ACCEPTED, review attribution/hash, optional one-to-one report/WO relation, entity versions, photo keys, and scoped-name uniqueness through a new migration; verify Prisma validation/generation and migration against clean and representative populated test databases, including multiple non-report WOs with null report IDs.
- [x] 1.4 Update schema-design documentation with invariants, preserved legacy fields, backfill behavior, and lifecycle boundaries; verify no original migration or historical business record is silently rewritten/deleted.

## 2. Hierarchy and read projections

- [x] 2.1 Add explicit shared asset/report DTOs in an authorized companion workspace and Assets routes/services/validators; verify create/read/name-update behavior, generated codes, role denials, archived-parent rejection, and protected-field rejection with API tests.
- [x] 2.2 Implement scoped name conflicts and versioned metadata edits; verify real MySQL concurrent duplicate creation and stale-edit tests, with no partial changes.
- [x] 2.3 Implement paginated category/equipment/sub-item navigation, matching search, and global summary; verify empty categories, matching descendants, distinct equipment counts, NOTED/CLEAN/UNKNOWN, archived exclusions, and due-today behavior.
- [x] 2.4 Add OpenAPI examples and query documentation for hierarchy endpoints; inspect representative query counts/plans to verify reads avoid per-row report queries and unbounded history loads.

## 3. Photos

- [x] 3.1 Add bounded multipart/image decoding dependencies after checking current documentation, and configure a persistent media-root adapter; verify genuine JPEG/PNG/WebP acceptance, spoofed content rejection, size/dimension limits, and no client-controlled path or URL fetch.
- [x] 3.2 Implement authenticated photo reads and versioned replacement/removal for assets and units; verify permission/CSRF behavior, restart persistence, correct content headers, and old-photo preservation on database failure/conflict.
- [x] 3.3 Add conservative unreferenced-file cleanup and document backup/restore and volume requirements; verify cleanup cannot escape its root or remove referenced/currently staged files, and document all media endpoints in OpenAPI.

## 4. Reporting and review

- [x] 4.1 Implement attributed sub-item report submission, paginated history/detail, and reviewer queue filters; verify roles, 1-3000-character descriptions, enum validation, server-generated actor/time, protected-field rejection, and no WO on submission; document contracts in OpenAPI.
- [x] 4.2 Implement Maintenance WO creation service taking the caller's transaction client and atomic Accept with normalized input hash; verify WO defaults, source/asset/reporter linkage, review/audit/history attribution, and complete rollback when a required write fails.
- [x] 4.3 Implement Dismiss with reason and replay/conflict handling; verify identical replay creates no new audit event and accepted/dismissed state conflicts produce 409.
- [x] 4.4 Run real MySQL tests for simultaneous Accept, Accept versus Dismiss, changed Accept input, and retry after lost response; verify one lifetime WO per report, one winning review, and no duplicated history/audit rows.
- [x] 4.5 Add bounded report/review rate limiting and review-action OpenAPI documentation; verify 429 envelopes, Retry-After, 201 first acceptance, 200 replay, and Location pointing to the persisted WO.

## 5. Consumer integration and Maintenance handoff

- [x] 5.1 Implement authenticated, paginated Work Order list/detail read APIs with safe DTOs and release-time filtering; verify accepted orders are immediately readable and document endpoints without exposing mutation operations.
- [ ] 5.2 In the authorized frontend workspace replace Pilot Plant IndexedDB writes with API-backed lists and ID-based forms, including separate photo upload; verify loading/error/empty states, role-aware actions, pagination, stale conflicts, and preservation of browser-local data.
- [ ] 5.3 Add report submission/history and admin/supervisor review queue with Accept/Dismiss; verify user-visible success follows committed responses, errors retain input, and report/asset/summary queries refresh after changes.
- [ ] 5.4 Add a read-only Maintenance view for persisted Pilot Plant corrective WOs and navigation from accepted reports; verify server records are not mixed with editable demo state and local status/parts forms cannot pretend to persist changes.
- [x] 5.5 Document consumer migration, read-only handoff limits, and future maintenance synchronization rules; verify cancellation/reopening/execution are not claimed as implemented and accepted reports remain active in condition counts.

## 6. Integrated release verification

- [ ] 6.1 Run API/shared/frontend typechecks, builds, existing regression suites, and new integration tests; record results, including isolated MySQL concurrency coverage and a browser flow from report submission through review to WO visibility.
- [ ] 6.2 Verify deployment readiness with configured persistent media storage, migration preflight results, database/media backup, and compatible rollback instructions; confirm baseline completion and companion frontend delivery before release.

## Workflow follow-up

- After implementation and review, sync/archive this change through OpenSpec.
- Plan Maintenance execution separately, enforcing IN_REPAIR/RESOLVED synchronization and cancellation/reopening of the same linked WO.
