-- Fix category redirects missing the category tree URL prefix in target_uri.
-- photo-wallpaper/categories/* redirects should point to the wall-murals tree.
-- canvas/categories/* redirects should point to the canvas tree.
--
-- Only rows where target_uri starts with '/' are updated. Rows that already
-- have the correct prefix do not start with '/' and are left untouched.
-- Verified by separate queries: zero rows exist with target_uri like '/{prefix}/...' so there is
-- no risk of double-prepending.

-- ============================================================
-- photo-wallpaper → wall-murals prefix per language
-- ============================================================

-- sv (market_locale_ids: 1)
UPDATE redirects
   SET target_uri = 'fototapet' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (1);

-- nn (market_locale_ids: 2)
UPDATE redirects
   SET target_uri = 'fototapet' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (2);

-- en (market_locale_ids: 3, 6, 10, 21, 23, 24, 25, 29, 58, 89, 90)
UPDATE redirects
   SET target_uri = 'wall-murals' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (3, 6, 10, 21, 23, 24, 25, 29, 58, 89, 90);

-- da (market_locale_ids: 4)
UPDATE redirects
   SET target_uri = 'fototapet' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (4);

-- fi (market_locale_ids: 5)
UPDATE redirects
   SET target_uri = 'valokuvatapetti' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (5);

-- de (market_locale_ids: 7, 9, 26, 30)
UPDATE redirects
   SET target_uri = 'fototapete' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (7, 9, 26, 30);

-- nl (market_locale_ids: 8, 16)
UPDATE redirects
   SET target_uri = 'fotobehang' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (8, 16);

-- es (market_locale_ids: 11)
UPDATE redirects
   SET target_uri = 'fotomurales' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (11);

-- fr (market_locale_ids: 12, 15, 22, 27, 31)
UPDATE redirects
   SET target_uri = 'papiers-peints-panoramiques' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (12, 15, 22, 27, 31);

-- pl (market_locale_ids: 13)
UPDATE redirects
   SET target_uri = 'fototapety' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (13);

-- it (market_locale_ids: 14, 28)
UPDATE redirects
   SET target_uri = 'fotomurale' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (14, 28);

-- ro (market_locale_ids: 56)
UPDATE redirects
   SET target_uri = 'fototapete' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (56);

-- pt (market_locale_ids: 57)
UPDATE redirects
   SET target_uri = 'murais-de-parede' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (57);

-- ja (market_locale_ids: 59)
UPDATE redirects
   SET target_uri = 'wall-murals' || target_uri
 WHERE source_uri LIKE '%photo-wallpaper/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (59);

-- ============================================================
-- canvas → canvas prefix per language
-- ============================================================

-- sv (market_locale_ids: 1)
UPDATE redirects
   SET target_uri = 'canvastavlor' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (1);

-- nn (market_locale_ids: 2)
UPDATE redirects
   SET target_uri = 'lerretsbilder' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (2);

-- en (market_locale_ids: 3, 6, 10, 21, 23, 24, 25, 29, 58, 89, 90)
UPDATE redirects
   SET target_uri = 'canvas-prints' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (3, 6, 10, 21, 23, 24, 25, 29, 58, 89, 90);

-- da (market_locale_ids: 4)
UPDATE redirects
   SET target_uri = 'billeder-pa-laerred' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (4);

-- fi (market_locale_ids: 5)
UPDATE redirects
   SET target_uri = 'canvastaulu' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (5);

-- de (market_locale_ids: 7, 9, 26, 30)
UPDATE redirects
   SET target_uri = 'leinwandbilder' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (7, 9, 26, 30);

-- nl (market_locale_ids: 8, 16)
UPDATE redirects
   SET target_uri = 'canvas' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (8, 16);

-- es (market_locale_ids: 11)
UPDATE redirects
   SET target_uri = 'lienzos' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (11);

-- fr (market_locale_ids: 12, 15, 22, 27, 31)
UPDATE redirects
   SET target_uri = 'impressions-sur-toile' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (12, 15, 22, 27, 31);

-- pl (market_locale_ids: 13)
UPDATE redirects
   SET target_uri = 'obrazy-na-plotnie' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (13);

-- it (market_locale_ids: 14, 28)
UPDATE redirects
   SET target_uri = 'stampe-su-tela' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (14, 28);

-- ro (market_locale_ids: 56)
UPDATE redirects
   SET target_uri = 'panza' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (56);

-- pt (market_locale_ids: 57)
UPDATE redirects
   SET target_uri = 'tela' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (57);

-- ja (market_locale_ids: 59)
UPDATE redirects
   SET target_uri = 'canvas-prints' || target_uri
 WHERE source_uri LIKE '%canvas/%categories%'
   AND target_uri LIKE '/%'
   AND market_locale_id IN (59);
