-- Split the single "Bank / Mobile Money" asset account into two:
--   1010 "Bank"          (role 'bank'          — keeps its existing code/id)
--   1020 "Mobile Money"  (role 'mobile_money'  — new)
--
-- Going forward Ledger::cashAccountId() routes mobile-money payment methods
-- (MTN/Airtel/MoMo, and the Yo! online collections) to Mobile Money, and bank
-- transfers/cheques to Bank. Historical entries stay where they were posted;
-- a one-off opening/true-up journal sets each account's real balance.
--
-- Idempotent — safe to re-run.

-- 1) Rename the combined account to just "Bank" (role stays 'bank').
UPDATE chart_of_accounts
SET name = 'Bank'
WHERE role = 'bank' AND name = 'Bank / Mobile Money';

-- 2) Give every farm a Mobile Money account if it doesn't already have one.
INSERT INTO chart_of_accounts (farm_id, code, name, type, role, map_key, is_system, sort_order)
SELECT f.id, '1020', 'Mobile Money', 'asset', 'mobile_money', NULL, 1, 2
FROM farms f
WHERE NOT EXISTS (
  SELECT 1 FROM chart_of_accounts c
  WHERE c.farm_id = f.id AND c.role = 'mobile_money'
);
