-- Idempotent: TR katalog kanonik yolu /arama-sonuclari; /listing → 301.
-- EN /listing rotasına dokunulmaz.

UPDATE routes
SET redirect_to = '/arama-sonuclari',
    redirect_status = 301,
    type = 'listing',
    entity_id = NULL,
    is_active = 1,
    updated_at = CURRENT_TIMESTAMP
WHERE locale = ''
  AND path = '/listing';

INSERT INTO routes (locale, path, type, entity_id, redirect_to, redirect_status, is_active, priority)
SELECT '', '/listing', 'listing', NULL, '/arama-sonuclari', 301, 1, 100
WHERE NOT EXISTS (SELECT 1 FROM routes WHERE locale = '' AND path = '/listing');

UPDATE nav_menu_items
SET url = '/arama-sonuclari',
    updated_at = CURRENT_TIMESTAMP
WHERE TRIM(url) = '/listing';

UPDATE footer_menu_items
SET url = '/arama-sonuclari',
    updated_at = CURRENT_TIMESTAMP
WHERE TRIM(url) = '/listing';

UPDATE routes
SET redirect_to = '/arama-sonuclari',
    updated_at = CURRENT_TIMESTAMP
WHERE locale = ''
  AND TRIM(COALESCE(redirect_to, '')) = '/listing';
