-- ============================================================
-- seed_all.sql — Komplett seed för kategorier + produkter
--
-- Seeden är ensam sanningskälla för kategorier.
-- Den rensar Category-tabellen och bygger upp allt från scratch.
-- Product.categoryId nollställs och sätts om av STEG 3.
--
-- Kör på servern:
--   DB_PASS=$(grep MARIADB_ROOT_PASSWORD .env | cut -d= -f2)
--   docker exec -i recipe-db mariadb -uroot -p"$DB_PASS" recipe_app < db/seeds/seed_all.sql
-- ============================================================


-- ============================================================
-- RESET: Rensa kategorier och koppla bort produkter
-- ============================================================
SET foreign_key_checks = 0;
TRUNCATE TABLE `Category`;
SET foreign_key_checks = 1;
UPDATE `Product` SET `categoryId` = NULL;


-- ============================================================
-- STEG 1: KATEGORIER (komplett träd — enda sanningskällan)
-- ============================================================

-- ── NIVÅ 1: Toppkategorier ───────────────────────────────────
INSERT INTO `Category` (`name`, `parentId`) VALUES ('Bröd & Kakor',         NULL);
INSERT INTO `Category` (`name`, `parentId`) VALUES ('Dryck',                NULL);
INSERT INTO `Category` (`name`, `parentId`) VALUES ('Färdigmat',            NULL);
INSERT INTO `Category` (`name`, `parentId`) VALUES ('Fryst',                NULL);
INSERT INTO `Category` (`name`, `parentId`) VALUES ('Frukt & Grönt',        NULL);
INSERT INTO `Category` (`name`, `parentId`) VALUES ('Glass, godis & snacks', NULL);
INSERT INTO `Category` (`name`, `parentId`) VALUES ('Kött, chark & fågel',  NULL);
INSERT INTO `Category` (`name`, `parentId`) VALUES ('Mejeri, ost & ägg',    NULL);
INSERT INTO `Category` (`name`, `parentId`) VALUES ('Skafferi',             NULL);
INSERT INTO `Category` (`name`, `parentId`) VALUES ('Fisk & Skaldjur',      NULL);
INSERT INTO `Category` (`name`, `parentId`) VALUES ('Vegetariskt',          NULL);

-- ── NIVÅ 2: under Bröd & Kakor ──────────────────────────────
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Bröd',               id FROM `Category` WHERE name = 'Bröd & Kakor'         AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Fastfoodbröd',       id FROM `Category` WHERE name = 'Bröd & Kakor'         AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Kex & Kakor',        id FROM `Category` WHERE name = 'Bröd & Kakor'         AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Knäckebröd & Skorpor', id FROM `Category` WHERE name = 'Bröd & Kakor'       AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Kondis & fika',      id FROM `Category` WHERE name = 'Bröd & Kakor'         AND parentId IS NULL;

-- ── NIVÅ 2: under Dryck ─────────────────────────────────────
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Öl & cider',           id FROM `Category` WHERE name = 'Dryck'              AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Läsk och Energidryck', id FROM `Category` WHERE name = 'Dryck'              AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Juice, fruktdryck & smoothie', id FROM `Category` WHERE name = 'Dryck'   AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Te & choklad',         id FROM `Category` WHERE name = 'Dryck'              AND parentId IS NULL;

-- ── NIVÅ 2: under Färdigmat ─────────────────────────────────
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Såser, grytbaser & övriga smaksättare', id FROM `Category` WHERE name = 'Färdigmat' AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Gratäng & Röror mm',   id FROM `Category` WHERE name = 'Färdigmat'          AND parentId IS NULL;

-- ── NIVÅ 2: under Fryst ─────────────────────────────────────
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Bageri',              id FROM `Category` WHERE name = 'Fryst'               AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Grönsaker & kryddor', id FROM `Category` WHERE name = 'Fryst'               AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Frukt & Bär',         id FROM `Category` WHERE name = 'Fryst'               AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Potatis',             id FROM `Category` WHERE name = 'Fryst'               AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Färdigmat',           id FROM `Category` WHERE name = 'Fryst'               AND parentId IS NULL;

-- ── NIVÅ 2: under Frukt & Grönt ─────────────────────────────
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Potatis & rotsaker',  id FROM `Category` WHERE name = 'Frukt & Grönt'       AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Kryddor & smaksättare', id FROM `Category` WHERE name = 'Frukt & Grönt'     AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Grönsaker',           id FROM `Category` WHERE name = 'Frukt & Grönt'       AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Frukt',               id FROM `Category` WHERE name = 'Frukt & Grönt'       AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Färska bär',          id FROM `Category` WHERE name = 'Frukt & Grönt'       AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Svamp',               id FROM `Category` WHERE name = 'Frukt & Grönt'       AND parentId IS NULL;

-- ── NIVÅ 2: under Glass, godis & snacks ─────────────────────
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Chips, snacks & dip', id FROM `Category` WHERE name = 'Glass, godis & snacks' AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Choklad',             id FROM `Category` WHERE name = 'Glass, godis & snacks' AND parentId IS NULL;

-- ── NIVÅ 2: under Kött, chark & fågel ───────────────────────
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Pålägg',              id FROM `Category` WHERE name = 'Kött, chark & fågel' AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Chark',               id FROM `Category` WHERE name = 'Kött, chark & fågel' AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Korv',                id FROM `Category` WHERE name = 'Kött, chark & fågel' AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Kött',                id FROM `Category` WHERE name = 'Kött, chark & fågel' AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Fågel',               id FROM `Category` WHERE name = 'Kött, chark & fågel' AND parentId IS NULL;

-- ── NIVÅ 2: under Mejeri, ost & ägg ─────────────────────────
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Ost',                  id FROM `Category` WHERE name = 'Mejeri, ost & ägg'  AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Allergi mejeri',       id FROM `Category` WHERE name = 'Mejeri, ost & ägg'  AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Mjölk',                id FROM `Category` WHERE name = 'Mejeri, ost & ägg'  AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Filmjölk & Yoghurt',   id FROM `Category` WHERE name = 'Mejeri, ost & ägg'  AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Matlagning',           id FROM `Category` WHERE name = 'Mejeri, ost & ägg'  AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Smör, margarin & jäst', id FROM `Category` WHERE name = 'Mejeri, ost & ägg' AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Havre-, Soja-, Risdryck mm', id FROM `Category` WHERE name = 'Mejeri, ost & ägg' AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Kvarg & Cottage cheese', id FROM `Category` WHERE name = 'Mejeri, ost & ägg' AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Mellanmål & desserter', id FROM `Category` WHERE name = 'Mejeri, ost & ägg' AND parentId IS NULL;

-- ── NIVÅ 2: under Skafferi ──────────────────────────────────
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Kryddor & smaksättare', id FROM `Category` WHERE name = 'Skafferi'          AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Pasta, ris & matgryn',  id FROM `Category` WHERE name = 'Skafferi'          AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Oliver & delikatesser', id FROM `Category` WHERE name = 'Skafferi'          AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Konserver & burkar',    id FROM `Category` WHERE name = 'Skafferi'          AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Asien',                 id FROM `Category` WHERE name = 'Skafferi'          AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Torkad frukt',          id FROM `Category` WHERE name = 'Skafferi'          AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Torra baljväxter',      id FROM `Category` WHERE name = 'Skafferi'          AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Flingor, gryner & musli', id FROM `Category` WHERE name = 'Skafferi'       AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Torr färdigmat',        id FROM `Category` WHERE name = 'Skafferi'          AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Bakning',               id FROM `Category` WHERE name = 'Skafferi'          AND parentId IS NULL;

-- ── NIVÅ 2: under Fisk & Skaldjur ────────────────────────────
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Fisk',                 id FROM `Category` WHERE name = 'Fisk & Skaldjur'   AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Sill, Ansjovis & Sardiner', id FROM `Category` WHERE name = 'Fisk & Skaldjur' AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Skaldjur & Havsdelikatesser', id FROM `Category` WHERE name = 'Fisk & Skaldjur' AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Lakeprodukter',       id FROM `Category` WHERE name = 'Fisk & Skaldjur'   AND parentId IS NULL;

-- ── NIVÅ 2: under Vegetariskt ──────────────────────────────────
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Fryst',                id FROM `Category` WHERE name = 'Vegetariskt'       AND parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`) SELECT 'Tofu',                 id FROM `Category` WHERE name = 'Vegetariskt'       AND parentId IS NULL;

-- ── NIVÅ 3: under Bröd & Kakor > Bröd ──────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Matbröd', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Bröd'
  WHERE c1.name = 'Bröd & Kakor' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Rostbröd', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Bröd'
  WHERE c1.name = 'Bröd & Kakor' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Bröd & Kakor > Kondis & fika ────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Kaffebröd', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kondis & fika'
  WHERE c1.name = 'Bröd & Kakor' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Bröd & Kakor > Fastfoodbröd ─────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Hamburgerbröd', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Fastfoodbröd'
  WHERE c1.name = 'Bröd & Kakor' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Bröd & Kakor > Kex & Kakor ───────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Matkex', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kex & Kakor'
  WHERE c1.name = 'Bröd & Kakor' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Söta kex & kakor', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kex & Kakor'
  WHERE c1.name = 'Bröd & Kakor' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Bröd & Kakor > Knäckebröd & Skorpor ──────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Knäckebröd', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Knäckebröd & Skorpor'
  WHERE c1.name = 'Bröd & Kakor' AND c1.parentId IS NULL;
-- ── NIVÅ 3: under Dryck > Juice, fruktdryck & smoothie ─────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Kyld juice & nektar', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Juice, fruktdryck & smoothie'
  WHERE c1.name = 'Dryck' AND c1.parentId IS NULL;
-- ── NIVÅ 3: under Dryck > Te & choklad ──────────────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Te', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Te & choklad'
  WHERE c1.name = 'Dryck' AND c1.parentId IS NULL;
-- ── NIVÅ 3: under Färdigmat > Såser, grytbaser... ───────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Dressing & övriga smaksättare', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Såser, grytbaser & övriga smaksättare'
  WHERE c1.name = 'Färdigmat' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Kylda såser', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Såser, grytbaser & övriga smaksättare'
  WHERE c1.name = 'Färdigmat' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Färdigmat > Gratäng & Röror mm ────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Krämiga sallader', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Gratäng & Röror mm'
  WHERE c1.name = 'Färdigmat' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Fryst > Bageri ────────────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Bröd & fikabröd', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Bageri'
  WHERE c1.name = 'Fryst' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Fryst > Grönsaker & kryddor ───────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Kryddor', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Grönsaker & kryddor'
  WHERE c1.name = 'Fryst' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Grönsaker', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Grönsaker & kryddor'
  WHERE c1.name = 'Fryst' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Fryst > Färdigmat ─────────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Pizza, paj & piroger', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Färdigmat'
  WHERE c1.name = 'Fryst' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Frukt & Grönt > Potatis & rotsaker ────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Lök', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Potatis & rotsaker'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Rotsaker', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Potatis & rotsaker'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Frukt & Grönt > Kryddor & smaksättare ─────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Smaksättare', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kryddor & smaksättare'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Kryddor & örter', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kryddor & smaksättare'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;
-- ── NIVÅ 3: under Frukt & Grönt > Grönsaker ─────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Bönor & Groddar', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Grönsaker'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)  SELECT 'Sallad & Kål', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Grönsaker'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Auberginer & Zucchini', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Grönsaker'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)  SELECT 'Paprika', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Grönsaker'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Övriga grönsaker', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Grönsaker'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Tomater', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Grönsaker'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Färdigskuret', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Grönsaker'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Frukt & Grönt > Frukt ─────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Druvor', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Frukt'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Citrusfrukt', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Frukt'
  WHERE c1.name = 'Frukt & Grönt' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Glass > Chips, snacks & dip ───────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Chips', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Chips, snacks & dip'
  WHERE c1.name = 'Glass, godis & snacks' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Glass > Choklad ───────────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Chokladkakor & rullar', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Choklad'
  WHERE c1.name = 'Glass, godis & snacks' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Kött, chark & fågel > Pålägg ──────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Korv & salami', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Pålägg'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Skivat pålägg', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Pålägg'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Kött, chark & fågel > Chark ─────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Köttbullar & färsprodukter', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Chark'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Kött, chark & fågel > Korv ───────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Ölkorv', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Korv'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Grill, kok- & kryddkorv', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Korv'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Vegetarisk korv', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Korv'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Kött, chark & fågel > Kött ────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Färdiglagat & pannfärdigt', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kött'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Nöt & kalv', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kött'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Köttfärs', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kött'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Fläsk', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kött'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Kött, chark & fågel > Fågel ───────────────
INSERT INTO `Category` (`name`, `parentId`)  SELECT 'Färsk fågel', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Fågel'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)  SELECT 'Fryst fågel', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Fågel'
  WHERE c1.name = 'Kött, chark & fågel' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Mejeri, ost & ägg > Ost ───────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Färskost', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Ost'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Dessertost', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Ost'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Matlagningsost', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Ost'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Mejeri, ost & ägg > Mjölk ─────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Standardmjölk', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Mjölk'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Mejeri, ost & ägg > Allergi mejeri ────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Laktosfri mjölk', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Allergi mejeri'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Filmjölk & Yoghurt', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Allergi mejeri'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Kvarg & Cottage cheese', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Allergi mejeri'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Matfett', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Allergi mejeri'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Mejeri, ost & ägg > Mjölk (standard) ───────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Standardmjölk', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Mjölk'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Mejeri, ost & ägg > Matlagning ──────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Gräddfil & creme fraiche', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Matlagning'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Matlagningsyoghurt', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Matlagning'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Allergi matlagning', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Matlagning'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Mejeri, ost & ägg > Smör, margarin & jäst ────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Matfett', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Smör, margarin & jäst'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Mejeri, ost & ägg > Filmjölk & Yoghurt ────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Filmjölk', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Filmjölk & Yoghurt'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Smaksatt yoghurt', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Filmjölk & Yoghurt'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Mejeri, ost & ägg > Kvarg & Cottage cheese ────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Kvarg & Cottage cheese', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kvarg & Cottage cheese'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Kvarg', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kvarg & Cottage cheese'
  WHERE c1.name = 'Mejeri, ost & ägg' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Skafferi > Kryddor & smaksättare ──────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Sås, dressing & majonnäs', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kryddor & smaksättare'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Kryddor', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kryddor & smaksättare'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Övriga smaksättare', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Kryddor & smaksättare'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Skafferi > Pasta, ris & matgryn ───────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Färsk pasta', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Pasta, ris & matgryn'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Pasta', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Pasta, ris & matgryn'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Skafferi > Oliver & delikatesser ──────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Delikatesser', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Oliver & delikatesser'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Skafferi > Konserver & burkar ─────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Tomatkonserver', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Konserver & burkar'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Fruktkonserver', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Konserver & burkar'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Grönsakskonserver', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Konserver & burkar'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Fisk- & skaldjurskonserver', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Konserver & burkar'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Skafferi > Asien ──────────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Såser & grytbaser', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Asien'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Nudlar', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Asien'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Skafferi > Torra baljväxter ───────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Fröer & kärnor', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Torra baljväxter'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Skafferi > Flingor, gryner & musli ──────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Granola', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Flingor, gryner & musli'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Fryst > Potatis ──────────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Pommes frites & strips', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Potatis'
  WHERE c1.name = 'Fryst' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Fryst > Färdigmat ────────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Övrig färdigmat', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Färdigmat'
  WHERE c1.name = 'Fryst' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Färdigmat enportioner', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Färdigmat'
  WHERE c1.name = 'Fryst' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Pizza, paj & piroger', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Färdigmat'
  WHERE c1.name = 'Fryst' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Skafferi > Bakning ────────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Baktillbehör', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Bakning'
  WHERE c1.name = 'Skafferi' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Fisk & Skaldjur > Fisk ────────────────────
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Fryst fisk', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Fisk'
  WHERE c1.name = 'Fisk & Skaldjur' AND c1.parentId IS NULL;
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Rökt & gravat', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Fisk'
  WHERE c1.name = 'Fisk & Skaldjur' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Fisk & Skaldjur > Sill, Ansjovis & Sardiner 
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Sill', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Sill, Ansjovis & Sardiner'
  WHERE c1.name = 'Fisk & Skaldjur' AND c1.parentId IS NULL;

-- ── NIVÅ 3: under Fisk & Skaldjur > Skaldjur & Havsdelikatesser
INSERT INTO `Category` (`name`, `parentId`)
  SELECT 'Frysta skaldjur & havsdelikatesser', c2.id FROM `Category` c1
  JOIN `Category` c2 ON c2.parentId = c1.id AND c2.name = 'Skaldjur & Havsdelikatesser'
  WHERE c1.name = 'Fisk & Skaldjur' AND c1.parentId IS NULL;
