-- t-paliad-112 B2: Fristenrechner deadline_notes_en column + EN backfill.
--
-- paliad.deadline_rules.deadline_notes was DE-only (12 wrote some German,
-- 029 added more German strings). When the locale flips to EN, the timeline
-- still emitted the German notes — visible leak on /tools/fristenrechner.
--
-- Fix: add a parallel deadline_notes_en column, backfill EN translations
-- for every existing row that has a deadline_notes value (30 rows today).
-- The render path will prefer _en when locale=EN and fall back to the DE
-- column when _en IS NULL (so future rows seeded without an EN translation
-- still render in DE rather than empty).
--
-- A handful of seed rows from 012 had English text in the (DE-named)
-- deadline_notes column already; those are copied verbatim into _en so
-- the EN locale stays consistent. The DE-leak in those 5 rows is a
-- separate bug (DE locale rendering English) and is intentionally not
-- fixed here — out of scope for this bundle.

ALTER TABLE paliad.deadline_rules
    ADD COLUMN IF NOT EXISTS deadline_notes_en text;

COMMENT ON COLUMN paliad.deadline_rules.deadline_notes_en IS
    'English translation of deadline_notes. Render path prefers this column '
    'when the active locale is EN; falls back to deadline_notes (DE) when NULL.';

-- ============================================================================
-- Backfill: 30 rows. Match by id (UUIDs from migrations 012 and 029).
-- Translations follow UPC RoP / EPC / ZPO terminology used elsewhere in the
-- codebase (i18n keys, model docstrings, changelog).
-- ============================================================================

UPDATE paliad.deadline_rules SET deadline_notes_en = CASE id
    -- 012 seeds: rows that already carry English text in deadline_notes.
    -- Copy verbatim so the EN locale is consistent regardless of DE-leak fix.
    WHEN 'a0807104-26e2-4277-95a7-72711817462f'::uuid -- inf.prelim (UPC_INF)
        THEN 'Rarely triggers separate decision; usually decided with main case'
    WHEN '6db004d3-af14-48db-aa43-a8265bce8360'::uuid -- ccr.interim (UPC_CCR)
        THEN 'May be combined with infringement IC'
    WHEN '44e1b960-87cf-41e2-a4d2-e83cabdde41c'::uuid -- ccr.reply (UPC_CCR)
        THEN 'Timing overlaps with infringement Rejoinder'
    WHEN 'c55edf56-f1db-4b49-b094-6dad2cc1a97e'::uuid -- pi.response (UPC_PI)
        THEN 'Deadline set by court'
    WHEN '0a8946d5-a77b-4d13-b0bd-79c31cda648f'::uuid -- app.grounds (UPC_APP)
        THEN 'Anchored on decision date (the trigger), not on filing of notice'

    -- 012 seeds: rows with German deadline_notes — translate to EN.
    WHEN 'ae12578b-9225-41eb-8c52-e0d19c3c47a6'::uuid -- zpo.vertanz (ZPO_INF)
        THEN 'Mandatory time limit (Notfrist); runs from service of the statement of claim'
    WHEN 'a9e53ff5-0dd6-4b87-83ff-c9091dbe5d56'::uuid -- zpo.klageerw (ZPO_INF)
        THEN 'Set by the court; at least 2 weeks'
    WHEN 'cdcc6242-31ab-477f-8f74-831fc07972bf'::uuid -- zpo.berufung (ZPO_INF)
        THEN 'Mandatory time limit (Notfrist); runs from service of the full written judgment'
    WHEN '7b118633-92b2-4c91-8512-6cb929288f10'::uuid -- inf.interim (internal INF)
        THEN 'Hearing date set by the court'
    WHEN '37b7792c-a064-4ca0-b93e-636817dee975'::uuid -- inf.cost_app (internal INF)
        THEN '1-month period from service of the main decision'
    WHEN '30ffe572-aa77-4dcb-9292-a4750289f75c'::uuid -- pi.response (internal PI)
        THEN 'Time limit set by the court'
    WHEN 'a0f88cd1-7d48-44ed-9ceb-0ad8f585ffb8'::uuid -- app.grounds (internal APP, German variant)
        THEN 'Runs from service of the appealed decision; not from filing of the notice of appeal'
    WHEN '1bc97653-9844-4520-a143-2447a3287152'::uuid -- app.cross_a (internal APP)
        THEN '3-month period from service of the statement of grounds of appeal (R.224.2(a))'
    WHEN '9abd66c3-4678-447c-9478-f727721fd4b6'::uuid -- de_inf.erwidg (DE_INF)
        THEN 'Standard time limit; extendable on request'
    WHEN 'd46d915e-fd46-4167-88b5-6d22bcbb8882'::uuid -- de_inf.replik (DE_INF)
        THEN 'Time limit set by the court'
    WHEN 'ca9b52cb-e986-4c3a-9e89-e799e6a6ac33'::uuid -- de_inf.duplik (DE_INF)
        THEN 'Time limit set by the court'
    WHEN '72601b13-1953-474d-91df-47fbae8df31b'::uuid -- de_inf.berufung (DE_INF)
        THEN 'Runs from service of the judgment'
    WHEN 'ec95d463-6b25-43b8-924d-d88bfb67eb3a'::uuid -- de_null.berufung (DE_NULL)
        THEN 'Runs from service of the judgment'
    WHEN '02acd5f7-0634-46c8-a895-4399ad17369e'::uuid -- epa_opp.beschwerde (EPA_OPP)
        THEN 'Runs from notification of the decision'
    WHEN '7f96f4fd-22b0-439c-928f-857eac1102c9'::uuid -- epa_app.begr (EPA_APP)
        THEN 'Runs from notification of the decision; not from filing of the notice of appeal'
    WHEN 'f1caa3b1-e80d-4277-8433-c8eb454b967f'::uuid -- epa_app.erwidg (EPA_APP)
        THEN 'Time limit set by the Board of Appeal'
    WHEN '63069ae5-e380-4db5-b020-d1856f31300c'::uuid -- ep_grant.search (EP_GRANT)
        THEN 'Indicative; may take longer in practice'
    WHEN 'b9fdd819-9195-4930-89ec-c691a192f3b4'::uuid -- ep_grant.publish (EP_GRANT)
        THEN 'Runs from priority date (or filing date when no priority is claimed)'
    WHEN '540ade94-cddb-465c-9bd8-4d17e2fb39fe'::uuid -- ep_grant.exam_req (EP_GRANT)
        THEN 'Runs from communication of the opportunity to request examination (R.70(2) EPC)'
    WHEN '83d4bf8a-28d6-4e21-a020-a804d760a6e4'::uuid -- ep_grant.approval (EP_GRANT)
        THEN 'Grant and printing fee'
    WHEN 'ff63af92-8fee-4d43-a16e-320ca7240fde'::uuid -- cost.leave_app (COST decision)
        THEN '15-day period from service of the cost decision'
    WHEN '92ec1cb3-2623-477a-95f5-9b830baa0af0'::uuid -- app_ord.with_leave (APP order)
        THEN '15-day period from service of the order or the leave-to-appeal decision'
    WHEN 'f963419e-ecb5-403b-9f6f-6289a68f9315'::uuid -- app_ord.discretion (APP order)
        THEN '15-day period from service of the decision refusing leave to appeal'
    WHEN '423f3d50-05b3-4e0f-9043-d4f54157bcf7'::uuid -- app_ord.cross (APP order)
        THEN '15-day period from service of the statement of grounds of appeal (R.224.2(b))'
    WHEN 'd5aee17d-090c-4141-90aa-1a80c91a1478'::uuid -- app_ord.cross_reply (APP order)
        THEN '15-day period from service of the cross-appeal'
    ELSE deadline_notes_en
END
WHERE id IN (
    'a0807104-26e2-4277-95a7-72711817462f'::uuid,
    '6db004d3-af14-48db-aa43-a8265bce8360'::uuid,
    '44e1b960-87cf-41e2-a4d2-e83cabdde41c'::uuid,
    'c55edf56-f1db-4b49-b094-6dad2cc1a97e'::uuid,
    '0a8946d5-a77b-4d13-b0bd-79c31cda648f'::uuid,
    'ae12578b-9225-41eb-8c52-e0d19c3c47a6'::uuid,
    'a9e53ff5-0dd6-4b87-83ff-c9091dbe5d56'::uuid,
    'cdcc6242-31ab-477f-8f74-831fc07972bf'::uuid,
    '7b118633-92b2-4c91-8512-6cb929288f10'::uuid,
    '37b7792c-a064-4ca0-b93e-636817dee975'::uuid,
    '30ffe572-aa77-4dcb-9292-a4750289f75c'::uuid,
    'a0f88cd1-7d48-44ed-9ceb-0ad8f585ffb8'::uuid,
    '1bc97653-9844-4520-a143-2447a3287152'::uuid,
    '9abd66c3-4678-447c-9478-f727721fd4b6'::uuid,
    'd46d915e-fd46-4167-88b5-6d22bcbb8882'::uuid,
    'ca9b52cb-e986-4c3a-9e89-e799e6a6ac33'::uuid,
    '72601b13-1953-474d-91df-47fbae8df31b'::uuid,
    'ec95d463-6b25-43b8-924d-d88bfb67eb3a'::uuid,
    '02acd5f7-0634-46c8-a895-4399ad17369e'::uuid,
    '7f96f4fd-22b0-439c-928f-857eac1102c9'::uuid,
    'f1caa3b1-e80d-4277-8433-c8eb454b967f'::uuid,
    '63069ae5-e380-4db5-b020-d1856f31300c'::uuid,
    'b9fdd819-9195-4930-89ec-c691a192f3b4'::uuid,
    '540ade94-cddb-465c-9bd8-4d17e2fb39fe'::uuid,
    '83d4bf8a-28d6-4e21-a020-a804d760a6e4'::uuid,
    'ff63af92-8fee-4d43-a16e-320ca7240fde'::uuid,
    '92ec1cb3-2623-477a-95f5-9b830baa0af0'::uuid,
    'f963419e-ecb5-403b-9f6f-6289a68f9315'::uuid,
    '423f3d50-05b3-4e0f-9043-d4f54157bcf7'::uuid,
    'd5aee17d-090c-4141-90aa-1a80c91a1478'::uuid
);
