-- 新增素材分类 SQL（2025-06-03）
-- 文件1：新房装修流程（4 个分类）+ 文件2：装备材料选择（44 个分类）

DO $$
DECLARE
    l1_cailiao_id bigint;
    l2_fengchuang_id bigint;
    l2_zhanshi_id bigint;
BEGIN
    -- ====================== 文件1：新房装修流程 ======================

    -- 二级：封窗镜（拆改改造类下，sort_order=4）
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('chaigai-fengchuang', '封窗镜', 46, 2, 4, 'active', NOW(), NOW())
    RETURNING id INTO l2_fengchuang_id;

    -- 三级：封窗施工-封窗镜
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('chaigai-fengchuang-fcsg', '封窗施工-封窗镜', l2_fengchuang_id, 3, 1, 'active', NOW(), NOW());

    -- 三级：装烟机灶具-主材安装镜（parent_id=189 主材安装镜，sort_order=9）
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('anzhuang-zhucai-zyjzj', '装烟机灶具-主材安装镜', 189, 3, 9, 'active', NOW(), NOW());

    -- 三级：家具进场摆放就位-软装进场镜（parent_id=219 软装进场镜，sort_order=2）
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('ruanzhuang-ruanchang-jjjcbfjw', '家具进场摆放就位-软装进场镜', 219, 3, 2, 'active', NOW(), NOW());

    -- ====================== 文件2：装备材料选择 ======================

    -- 一级：装修材料选择（sort_order=90）
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao', '装修材料选择', NULL, 1, 90, 'active', NOW(), NOW())
    RETURNING id INTO l1_cailiao_id;

    -- 二级：材料展示
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi', '材料展示', l1_cailiao_id, 2, 1, 'active', NOW(), NOW())
    RETURNING id INTO l2_zhanshi_id;

    -- 三级：XX买谁家 + 品牌组合（42 个）
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-bxmsj', '冰箱买谁家', l2_zhanshi_id, 3, 1, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-dsmsj', '电视买谁家', l2_zhanshi_id, 3, 2, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-hsj', '花洒哪家好', l2_zhanshi_id, 3, 3, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-dxmsj', '电线买谁家', l2_zhanshi_id, 3, 4, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-yjj', '烟机哪家好', l2_zhanshi_id, 3, 5, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-rjqmsj', '乳胶漆买谁家', l2_zhanshi_id, 3, 6, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-kgczmsj', '开关插座买谁家', l2_zhanshi_id, 3, 7, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-czj', '瓷砖哪家好', l2_zhanshi_id, 3, 8, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-sgmsj', '水管买谁家', l2_zhanshi_id, 3, 9, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-bcxsj', '板材选谁家', l2_zhanshi_id, 3, 10, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-fsmsj', '防水买谁家', l2_zhanshi_id, 3, 11, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-ddxsj', '吊顶选谁家', l2_zhanshi_id, 3, 12, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-dbj', '地板哪家好', l2_zhanshi_id, 3, 13, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-nzfj', '腻子粉哪家好', l2_zhanshi_id, 3, 14, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-dlsj', '地漏谁家好', l2_zhanshi_id, 3, 15, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-jzsgsj', '家装水管谁家好', l2_zhanshi_id, 3, 16, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-jzsnsj', '家装水泥谁家好', l2_zhanshi_id, 3, 17, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-cwwjsj', '厨卫五金谁家好', l2_zhanshi_id, 3, 18, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-sgbsj', '石膏板谁家好', l2_zhanshi_id, 3, 19, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-czjsj', '瓷砖胶谁家好', l2_zhanshi_id, 3, 20, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-bljsj', '玻璃胶谁家好', l2_zhanshi_id, 3, 21, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-hemdksd', '海尔美的卡萨帝', l2_zhanshi_id, 3, 22, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-snhxtcl', '索尼海信TCL', l2_zhanshi_id, 3, 23, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-jmhjjp', '九牧恒洁箭牌', l2_zhanshi_id, 3, 24, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-ydbsxm', '远东宝胜熊猫', l2_zhanshi_id, 3, 25, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-ftlbhd', '方太老板华帝', l2_zhanshi_id, 3, 26, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-lbsksdls', '立邦三棵树多乐士', l2_zhanshi_id, 3, 27, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-gnsndxmz', '公牛施耐德西门子', l2_zhanshi_id, 3, 28, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-dpgzmkbl', '东鹏冠珠马可波罗', l2_zhanshi_id, 3, 29, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-rfwxbl', '日丰伟星保利', l2_zhanshi_id, 3, 30, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-whagtbb', '万华爱格兔宝宝', l2_zhanshi_id, 3, 31, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-lbdgdfyh', '立邦德高东方雨虹', l2_zhanshi_id, 3, 32, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-apybfsl', '奥普友邦法狮龙', l2_zhanshi_id, 3, 33, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-sxsydzr', '圣象世友大自然', l2_zhanshi_id, 3, 34, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-lbmcsgb', '立邦美巢圣戈邦', l2_zhanshi_id, 3, 35, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-jmjpqst', '九牧箭牌潜水艇', l2_zhanshi_id, 3, 36, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-jnwxrf', '金牛伟星日丰', l2_zhanshi_id, 3, 37, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-hlhszl', '海螺红狮中联', l2_zhanshi_id, 3, 38, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-kljmhsgy', '科勒九牧汉斯格雅', l2_zhanshi_id, 3, 39, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-lptsknf', '龙牌泰山可耐福', l2_zhanshi_id, 3, 40, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-dgxkm', '德高西卡马贝', l2_zhanshi_id, 3, 41, 'active', NOW(), NOW());
    INSERT INTO mjk_broll_categories (slug, name, parent_id, level, sort_order, status, created_at, updated_at)
    VALUES ('cailiao-zhanshi-wkxkbd', '瓦克西卡百得', l2_zhanshi_id, 3, 42, 'active', NOW(), NOW());

END $$;
