-- ═══════════════════════════════════════════════════════════════════════════
--  COMPLETE EXAMPLE — engage two formulas with the "lo-shu-deep-dive" service.
--  Tables self-create on first use (Masters engine); run these inserts after.
--  (id / is_active / timestamps are added automatically by the engine.)
-- ═══════════════════════════════════════════════════════════════════════════

-- 1) FORMULA DEFINITIONS -----------------------------------------------------

-- (A) CODE formula = YOUR algorithm (handler class). No master query.
INSERT INTO formula_definitions
  (formula_key, name, category, type, handler, source_master, match_config, select_config, output_template, params_schema, status)
VALUES
  ('num.lo_shu_missing', 'Lo Shu — Missing Numbers', 'numerology', 'code',
   'App\\\\Services\\\\Formula\\\\Handlers\\\\SampleLoShuMissingNumbers',
   '', '', '', '', '{"weight":1.0}', 'active');

-- (B) QUERY formula = data-driven, reads YOUR rule master (num_rules).
INSERT INTO formula_definitions
  (formula_key, name, category, type, handler, source_master, match_config, select_config, output_template, params_schema, status)
VALUES
  ('num.grid_rules', 'Numerology Grid Rules', 'numerology', 'query',
   '', 'num_rules',
   '{"where":[{"col":"calc_key","op":"=","ctx":"calc_key"},{"col":"number","op":"=","ctx":"number"}],"active_col":"is_active"}',
   '{"order":[{"col":"priority","dir":"desc"}],"limit":20,"score_col":"score_impact","lang_fields":["finding","explanation"],"row_template":"<p><b>{{finding}}</b>{{explanation_sep}}{{explanation}}</p>"}',
   '<div class="formula-block"><h4>Grid Insights</h4>{{rows}}</div>',
   '{}', 'active');

-- 2) SERVICE ↔ FORMULA BINDINGS ---------------------------------------------
--    Engage BOTH formulas with the paid report service "lo-shu-deep-dive".

INSERT INTO service_formula_bindings
  (binding_code, svc_context, service_slug, formula_key, sequence, params, output_slot, mode, `condition`, status)
VALUES
  ('BIND-LOSHU-1', 'report_service', 'lo-shu-deep-dive', 'num.lo_shu_missing', 1, '{"weight":1.0}', 'predictions', 'append', '', 'active'),
  ('BIND-GRID-1',  'report_service', 'lo-shu-deep-dive', 'num.grid_rules',     2, '{}',            'predictions', 'append', '', 'active');
