Engine

The auto-pause engine

When a SKU hits zero, the engine pauses every ad campaign attached to it. When stock returns above the buffer, it resumes. Every decision is logged with the reason and timestamp.

Rule
The decision is a pure function — one stock number in, one action out.

stock = 0→ PAUSE the campaign.

stock > buffer→ RESUME the campaign.

0 < stock ≤ buffer→ NOOP (wait).

Already-paused-by-engine is sticky: re-evaluating stock = 0 stays NOOP until stock returns above buffer.

Providers
Resolved per watch — mock by default, live when the env is wired.

Mock— records a successful pause/resume locally so the status table updates end-to-end without real credentials.

Live— calls Meta, Google, and TikTok based on the watch’s provider field.