#pragma once // Read/write access to the `rules` table (rules.list / rules.upsert / capture.offer's own // read path). match/action are stored as their generated-JSON text (velox::proto::RuleMatch // / RuleAction), so no bespoke schema lives here beyond the table's own columns. #include #include #include "store/sqlite.hpp" #include "velox_proto.hpp" namespace velox::daemon::store { class Rules { public: explicit Rules(Db& db) : db_(db) {} // Enabled and disabled rules alike, in priority order (ties broken by rule_id) — // rules.list's own contract ("the rules engine's table, in priority order"); capture // offer's own caller filters to enabled ones itself, same as vdm::rules::match_rules // already does internally. DbResult> list(); // rules.upsert: "upsert carries the rules to store and remove the ruleIds to drop; // applying both at once means a reprioritisation never leaves the table in a // half-valid state" (the schema's own words) — one transaction. An empty ruleId in // `upsert` generates one (create); a non-empty one replaces. Returns the full table // after the write, in priority order. DbResult> apply(std::vector upsert, const std::vector& remove); private: Db& db_; }; } // namespace velox::daemon::store