-- t-paliad-207 (m's interactive session) — two label/priority polish
-- fixes on upc.inf.cfi / upc.rev.cfi:
--
-- 1. **CCR priority informational → optional.** m's correction
--    2026-05-18 18:01: the Nichtigkeitswiderklage is a substantive
--    defensive choice the defendant makes — not just an informational
--    notice. priority='optional' renders it as an unchecked save row
--    the user can opt into. The fermi amend (commit e8d658a) flipping
--    this didn't land in main — paliadin's merge of mig 100 (commit
--    c10f8cf, merge 4ddcd28) picked up the pre-amend 'informational'
--    version. This is the recovery.
--
-- 2. **Strip rule citation from Einspruch names.** m's correction
--    2026-05-18 18:08: every other rule name in the corpus carries
--    the act-name without a parenthetical rule cite (Klageerwiderung,
--    Antrag auf Patentänderung, Replik, etc.). The Einspruch rule
--    names are the outliers:
--      upc.inf.cfi.prelim  "Einspruch (R. 19 VerfO)"            → "Einspruch"
--      upc.rev.cfi.prelim  "Einspruch (R. 19 i.V.m. R. 46 VerfO)" → "Einspruch"
--    and EN equivalents:
--      "Preliminary Objection (RoP 19)" → "Preliminary Objection"
--      "Preliminary Objection (RoP 19 in conjunction with RoP 46)"
--                                      → "Preliminary Objection"
--    The legal_source / rule_code columns already carry the citation
--    and render in the deadline card's meta line, so the name stays
--    clean. The R.46-i.V.m. distinction is preserved in the legal
--    source field (RoP.019.1 for both — m may want to further
--    differentiate; flagged in description text instead).
--
-- audit_reason set_config required at the top — the deadline_rules
-- audit trigger raises EXCEPTION 'audit reason required' on any
-- mutation without it (cf. mig 099 hotfix history).
--
-- Idempotency:
--   * Priority UPDATE guarded on the current 'informational' value.
--   * Name UPDATEs guarded on the current parenthetical-bearing names.

SELECT set_config(
    'paliad.audit_reason',
    'mig 104: flip upc.inf.cfi.ccr priority informational→optional + strip rule-cite brackets from R.19 Einspruch names on both upc.inf.cfi.prelim and upc.rev.cfi.prelim (m''s corrections 2026-05-18, t-paliad-207 interactive session)',
    true);

-- 1) Flip CCR priority
UPDATE paliad.deadline_rules dr
   SET priority = 'optional'
  FROM paliad.proceeding_types pt
 WHERE dr.proceeding_type_id = pt.id
   AND pt.code = 'upc.inf.cfi'
   AND dr.submission_code = 'upc.inf.cfi.ccr'
   AND dr.lifecycle_state = 'published'
   AND dr.priority = 'informational';

-- 2a) Strip "(R. 19 VerfO)" from upc.inf.cfi.prelim DE/EN names
UPDATE paliad.deadline_rules dr
   SET name = 'Einspruch'
  FROM paliad.proceeding_types pt
 WHERE dr.proceeding_type_id = pt.id
   AND pt.code = 'upc.inf.cfi'
   AND dr.submission_code = 'upc.inf.cfi.prelim'
   AND dr.lifecycle_state = 'published'
   AND dr.name = 'Einspruch (R. 19 VerfO)';

UPDATE paliad.deadline_rules dr
   SET name_en = 'Preliminary Objection'
  FROM paliad.proceeding_types pt
 WHERE dr.proceeding_type_id = pt.id
   AND pt.code = 'upc.inf.cfi'
   AND dr.submission_code = 'upc.inf.cfi.prelim'
   AND dr.lifecycle_state = 'published'
   AND dr.name_en = 'Preliminary Objection (RoP 19)';

-- 2b) Strip "(R. 19 i.V.m. R. 46 VerfO)" from upc.rev.cfi.prelim DE/EN names
UPDATE paliad.deadline_rules dr
   SET name = 'Einspruch'
  FROM paliad.proceeding_types pt
 WHERE dr.proceeding_type_id = pt.id
   AND pt.code = 'upc.rev.cfi'
   AND dr.submission_code = 'upc.rev.cfi.prelim'
   AND dr.lifecycle_state = 'published'
   AND dr.name = 'Einspruch (R. 19 i.V.m. R. 46 VerfO)';

UPDATE paliad.deadline_rules dr
   SET name_en = 'Preliminary Objection'
  FROM paliad.proceeding_types pt
 WHERE dr.proceeding_type_id = pt.id
   AND pt.code = 'upc.rev.cfi'
   AND dr.submission_code = 'upc.rev.cfi.prelim'
   AND dr.lifecycle_state = 'published'
   AND dr.name_en = 'Preliminary Objection (RoP 19 in conjunction with RoP 46)';
