Source document
docs/platform/BOOKING-LIFECYCLE.md
Source version
0.0.0
Generated time
2026-07-06T14:59:22.701Z
Owner
Unassigned
Audience
Internal
Status
Approved

BOOKING LIFECYCLE — State Machine (Stage Beta-2)

Vòng đời Reservation: trạng thái, transition hợp lệ/không hợp lệ, invariant. Nguồn sự thật = code reservation-status.ts (state machine đã enforce + test). Nối: BOOKING-FLOW, platform-architecture/UNIVERSAL-BOOKING-MODEL.

State machine (CURRENT — đúng code)

pending ──▶ confirmed ──▶ checked_in ──▶ checked_out (terminal)
   │            │
   ├──▶ cancelled (terminal)      confirmed ──▶ cancelled / no_show
   ▼
cancelled
Trạng tháiÝ nghĩaTransition ĐI hợp lệ
pendingVừa tạo, đã giữ chỗconfirmed, cancelled
confirmedXác nhận (giữ chỗ chắc)checked_in, cancelled, no_show
checked_inKhách đã nhậnchecked_out
checked_outHoàn tất lưu trú (≈ Completed)— (terminal)
cancelledĐã huỷ— (terminal)
no_showKhông đến (giữ chỗ KHÔNG hoàn)— (terminal)
Completed ánh xạ checked_out. Expired = PROPOSED (giữ chỗ chưa thanh toán hết hạn) — chưa hiện thực (backlog Beta, UNIVERSAL-BOOKING-MODEL §7).

Transition KHÔNG hợp lệ (bị chặn)

Invariant từng trạng thái

Trạng tháiInvariant
pendingĐã giữ chỗ (Availability trừ tồn); giá snapshot bất biến; tenant-scoped
confirmedVẫn giữ chỗ; tính doanh thu (REVENUE_STATUSES)
checked_in/outChuỗi fulfillment lưu trú; checked_out tính doanh thu
cancelledHoàn tồn kho (held suy từ reservation non-cancelled ⇒ chỗ tự do lại); đơn bất biến sau huỷ
no_showKHÔNG hoàn tồn (chỗ coi như tiêu tốn); tính/không doanh thu theo policy (MVP: không)

Inventory ↔ lifecycle

Audit (mỗi transition thành công)

Cùng transaction (atomic): reservation.created (pending), reservation.confirmed, reservation.cancelled — append-only ([platform-policy]/[Audit Phase 2B]). Verify: audit đủ chuỗi trong E2E test.

Verify tự động

packages/platform-infrastructure/src/__tests__/booking-lifecycle-e2e.test.ts (6 test): confirm · cancel · confirm→cancel · double-cancel reject · inventory hoàn trả · audit đủ chuỗi. Demo tay: demo/BOOKING-LIFECYCLE-DEMO.