-- Reverses 031_tier2_fristenrechner_ports.up.sql.
-- Drops the seeded rules and the new proceeding types in FK-safe order.

-- Remove rules first (parent_id chains within each tree resolve via cascade
-- when the proceeding_type row is dropped, but we delete explicitly so a
-- partial seed is also cleared).
DELETE FROM paliad.deadline_rules
 WHERE proceeding_type_id IN (
        SELECT id FROM paliad.proceeding_types
         WHERE code IN ('UPC_DAMAGES','UPC_DISCOVERY','UPC_COST_APPEAL','UPC_APP_ORDERS')
   );

-- The single rule added to UPC_INF and the pair added to UPC_APP.
DELETE FROM paliad.deadline_rules
 WHERE proceeding_type_id = (SELECT id FROM paliad.proceeding_types WHERE code = 'UPC_INF')
   AND code = 'inf.cost_app';

DELETE FROM paliad.deadline_rules
 WHERE proceeding_type_id = (SELECT id FROM paliad.proceeding_types WHERE code = 'UPC_APP')
   AND code IN ('app.cross_a', 'app.cross_a_reply');

-- Drop the proceeding types last.
DELETE FROM paliad.proceeding_types
 WHERE code IN ('UPC_DAMAGES','UPC_DISCOVERY','UPC_COST_APPEAL','UPC_APP_ORDERS');
