-- Idempotent: üretim vitrininde kalan test içeriği, hero TEST görseli, bilinen slug 301, test adresi düzeltmesi.
-- Sonrası: Admin «Rotaları senkronize et» + route önbelleği temizle (gerekirse).

-- Demo / test ürünler (genişletilmiş slug listesi; LIKE yok)
UPDATE products
SET is_active = 0, show_on_home = 0
WHERE is_active = 1
  AND (
    LOWER(TRIM(title)) IN (
      'test',
      'demo',
      'mock',
      'deneme',
      'sample',
      'lorem ipsum',
      'test2',
      'test 2',
      'test 1',
      'test ürünü',
      'test urunu',
      'test urun',
      'örnek ürün',
      'ornek urun',
      'örnek',
      'ornek',
      'mock ürün',
      'demo ürün',
      'deneme ürünü',
      'taslak ürün',
      'api gateway',
      'edge router',
      'klinik randevu',
      'veysel test',
      'veysel tr',
      'veysel test tr',
      'test 3',
      'test3'
    )
    OR LOWER(TRIM(slug)) IN (
      'test',
      'demo',
      'mock',
      'sample',
      'deneme',
      'ornek-urun',
      'test-urun',
      'test-urunu',
      'test-1',
      'test-2',
      'test-3',
      'test3',
      'lorem-ipsum',
      'demo-urun',
      'mock-product',
      'demo-product',
      'test-product',
      'api-gateway',
      'edge-router',
      'klinik-randevu',
      'veysel-test',
      'veysel-test-2',
      'veysel-test-tr',
      'veysel2'
    )
  );

-- Bilinen eski ürün slug → güncel kanonik (ürün pasif olsa bile net 301)
INSERT INTO routes (locale, path, type, entity_id, redirect_to, redirect_status, is_active, priority)
SELECT '', '/veysel-test-2', 'product', NULL, '/veysel2', 301, 1, 30
WHERE NOT EXISTS (SELECT 1 FROM routes r WHERE r.locale = '' AND r.path = '/veysel-test-2');

UPDATE routes
SET redirect_to = '/veysel2', redirect_status = 301, entity_id = NULL, type = 'product', is_active = 1,
    updated_at = CURRENT_TIMESTAMP
WHERE locale = '' AND path = '/veysel-test-2';

INSERT INTO routes (locale, path, type, entity_id, redirect_to, redirect_status, is_active, priority)
SELECT '', '/veysel-test-tr', 'product', NULL, '/veysel2', 301, 1, 30
WHERE NOT EXISTS (SELECT 1 FROM routes r WHERE r.locale = '' AND r.path = '/veysel-test-tr');

UPDATE routes
SET redirect_to = '/veysel2', redirect_status = 301, entity_id = NULL, type = 'product', is_active = 1,
    updated_at = CURRENT_TIMESTAMP
WHERE locale = '' AND path = '/veysel-test-tr';

INSERT INTO routes (locale, path, type, entity_id, redirect_to, redirect_status, is_active, priority)
SELECT '', '/urun/veysel-test-2', 'product', NULL, '/veysel2', 301, 1, 30
WHERE NOT EXISTS (SELECT 1 FROM routes r WHERE r.locale = '' AND r.path = '/urun/veysel-test-2');

UPDATE routes
SET redirect_to = '/veysel2', redirect_status = 301, entity_id = NULL, type = 'product', is_active = 1,
    updated_at = CURRENT_TIMESTAMP
WHERE locale = '' AND path = '/urun/veysel-test-2';

-- Stale: eski path hâlâ entity_id ile ürün sunuyorsa redirect önceliği
UPDATE routes
SET entity_id = NULL, redirect_to = '/veysel2', redirect_status = 301, type = 'product', is_active = 1,
    updated_at = CURRENT_TIMESTAMP
WHERE locale = ''
  AND path IN ('/veysel-test-2', '/veysel-test-tr', '/urun/veysel-test-2')
  AND (redirect_to IS NULL OR TRIM(redirect_to) = '');

-- Hero: TEST watermark / test yükleme yollarını varsayılan SVG ile değiştir
UPDATE home_hero_slides
SET image_path = CASE sort_order
    WHEN 0 THEN '/hero/hero-1.svg'
    WHEN 1 THEN '/hero/hero-2.svg'
    ELSE '/hero/hero-3.svg'
  END,
  updated_at = CURRENT_TIMESTAMP
WHERE LOWER(image_path) LIKE '%test%'
   OR LOWER(COALESCE(alt_text, '')) LIKE '%test watermark%';

-- İletişim: panelde kalan Uşak / Karahallı test adresini Fethiye ile hizala
UPDATE site_settings
SET data_json = JSON_SET(
  COALESCE(NULLIF(TRIM(data_json), ''), '{}'),
  '$.address', 'Fethiye, Muğla, Türkiye',
  '$.maps_url', 'https://www.google.com/maps/search/?api=1&query=Fethiye+Mu%C4%9Fla+Faunamix'
)
WHERE section_key = 'contact'
  AND (
    LOWER(data_json) LIKE '%uşak%'
    OR LOWER(data_json) LIKE '%usak%'
    OR LOWER(data_json) LIKE '%karahall%'
    OR LOWER(data_json) LIKE '%karahalli%'
  );
