capacity-plans
CapacityPlan creation, publication and lookup (Phase 4).
List the most recent CapacityPlans
The most recently created plans, newest first (ties broken by id, descending), each in exactly the shape of GET /capacity-plans/{id}, one keyset page at a time (limit + cursor; follow nextCursor until it is absent). `location`, `site_id`, `path_id`, `window_start` and `window_end` are optional, ADDITIVE filters (docs/adr/0024): a plan is listed only when it matches every filter sent; an omitted or empty one does not filter (repeat them on every page request). Together site_id, path_id and the window list the what-if scenarios of one window. 200 with an empty items list when nothing matches. Read-only; there is no MCP tool for it.
Create a DRAFT CapacityPlan and compute its shortage
Evaluates the ProcessPath path_id against assigned_demand (orders) for the warehouse's location over [window_start, window_end): loads each step's ProcessCapacity, normalizes it with the WorkloadProfile factors supplied in the body (same shape and validation as GET /process-paths/{id}/capacity -- there is no WorkloadProfile persistence yet), and computes path_capacity (ORDER per HOUR), bottleneck_step, capacity_over_window (path_capacity x window hours) and shortage (max(0, assigned_demand - capacity_over_window), never negative). The window is both the plan's planning window AND the window every step's ProcessCapacity is looked up for: a registered window applies to a step when it COVERS [window_start, window_end), exactly as in GET /process-paths/{id}/capacity (docs/adr/0003). The plan stores its own requested window. site_id is REQUIRED: the canonical site (a facility-layout Site site_code, the same identifier its SiteCapabilityChanged event publishes) the plan is scoped to. It is a stated planning fact, never inferred from warehouse_id or location, and a blank or absent one is rejected with 422 missing-required-field. assigned_demand is OPTIONAL (docs/adr/0004). An explicit value (including 0) is used exactly as stated and the plan's demand_source is 'request'. When it is OMITTED the demand defaults to the number of orders the local read model -- fed by order-management's published OrderAllocated / OrderPartiallyAllocated events, never by a live call -- expects at `location` in [window_start, window_end) (see GET /demand), the plan's demand_source is 'orders', and assigned_demand in the response is that figure. When the read model has no order for that location and window the request is rejected with 422 missing-assigned-demand: absence never silently means zero demand. demand_source (docs/adr/0024) may name the source instead: 'forecast' derives assigned_demand from the workload forecast of (site_id, forecast_path_id, default path_id) -- the units of the buckets whose cpt is in the window over units_per_order, rounded up to orders -- and the plan returns forecast_path_id. labour_requirement (docs/adr/0022) states, per path step, the labour its demand requires: tasks x the standard seconds of the step's task type, read from the local copy of labor-performance's labour standards (fed by its LaborStandardDefined / LaborStandardRevised events, never by a live call) for the plan's site at window_start. The optional tasks_per_order map counts a step's tasks; a step without a standard or without a task count is known false with a reason. It is informational: the shortage, the bottleneck and every published event are unchanged by it. The plan is saved and its CapacityPlanCreated event is queued in the transactional outbox in ONE database transaction.
Lay 2 to 5 capacity plan scenarios of one site and window side by side
docs/adr/0024 decision 4. ids names 2 to 5 distinct stored plans, all of one site_id and one window (same window_start and window_end); their paths, locations and statuses may differ. Per plan, in the order of ids, it returns the scenario, status, assigned demand and its source, path capacity, capacity over the window, shortage, bottleneck step and constraint and the ADR 0022 labour requirement exactly as stored when the plan was created: nothing is recomputed, so a comparison is reproducible. Read-only; REST only (no MCP tool).
Get a CapacityPlan
Returns the stored plan, including its computed shortage, status, the constraint type binding the bottleneck step and the composition warnings.
Publish a DRAFT CapacityPlan
Moves the plan DRAFT -> PUBLISHED, saves it and queues, in the same database transaction, CapacityPlanPublished plus -- only when the plan has a shortage -- CapacityShortageDetected and BottleneckDetected in the transactional outbox. A relay publishes them to Kafka as CloudEvents (see asyncapi.yaml). Publishing twice is never silent: the second call is a 409 and queues nothing. Publishing supersedes (docs/adr/0024 decision 3): when another plan of the same site_id, location, path_id and window is PUBLISHED, that older plan becomes SUPERSEDED (superseded_by: this plan) and CapacityPlanSuperseded is queued first, in the same transaction. A SUPERSEDED plan is never published again (409).