-- t-paliad-133 Phase A backfill: tag genuinely-bilateral deadline rules.
--
-- Most rules with primary_party='both' are role-swap appeals — either
-- party can file depending on who lost / acted at the lower instance.
-- Those resolve at render time via the new perspective selector
-- (?my_side= + ?appeal_filed_by=). The renderer assigns them to ONE
-- column based on perspective.
--
-- The exceptions are GENUINELY BILATERAL rules — both parties can or
-- must file independently of who acted before. These mirror into BOTH
-- party columns of the v3 column-timeline view.
--
-- Set is_bilateral=true ONLY for:
--   • Stellungnahme zum Hinweisbeschluss (DE_NULL §83(2)) — both parties
--     comment on the court's preliminary opinion.
--   • R.79 Stellungnahme weiterer Beteiligter (EPA_OPP) — multi-party
--     opposition; all parties may submit.
--   • R.116 Eingaben vor mündl. Verhandlung (EPA_OPP, EPA_APP) — every
--     party prepares submissions before the oral hearing.
--
-- The cross-cutting schriftsatznachreichung lives in event_deadlines
-- (not deadline_rules), so its bilateral nature is handled by the
-- frontend renderer separately — no DB change needed.
--
-- Spot-checkable list of 4 rules; m or HLC colleague reviews on this
-- commit.

UPDATE paliad.deadline_rules
   SET is_bilateral = true
 WHERE code IN (
        'de_null.stellungnahme',
        'epa_opp.r79_further',
        'epa_opp.r116',
        'epa_app.r116'
       )
   AND is_active = true;

-- Sanity check: exactly 4 rules tagged.
DO $check$
DECLARE
    tagged int;
BEGIN
    SELECT count(*) INTO tagged
      FROM paliad.deadline_rules
     WHERE is_bilateral = true;
    IF tagged <> 4 THEN
        RAISE EXCEPTION
          'Phase A bilateral backfill: expected 4 rules tagged, got %',
          tagged;
    END IF;
END $check$;
