-- Seed: 医疗商城首页分类与示例商品关联
-- 依赖: public.medical_mall_categories / public.medical_mall_product_categories / public.ml_products

BEGIN;

INSERT INTO public.medical_mall_categories (
    id, name, parent_id, level, sort_order, icon, image_url, description, scene, category_type, compliance_type, is_active, created_at, updated_at
)
VALUES
('med_device', '医疗器械', NULL, 1, 10, '🩺', NULL, '家庭监测与基础器械', 'medical_mall', 'device', 'device_class_i', TRUE, NOW(), NOW()),
('otc_medicine', '家庭常备药', NULL, 1, 20, '💊', NULL, 'OTC 家庭常备药与应急用药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()),
('rehab_care', '康复护理', NULL, 1, 30, '🩹', NULL, '术后恢复、敷料护具与护理用品', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()),
('chronic_monitor', '慢病监测', NULL, 1, 40, '📈', NULL, '高血压、糖尿病与家庭检测场景', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('elderly_aid', '适老用品', NULL, 1, 50, '🧓', NULL, '长者安全辅助与居家适老用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()),
('nutrition_health', '营养保健', NULL, 1, 60, '🥛', NULL, '维生素、钙片、蛋白营养等保健品', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()),
('protection_disinfection', '防护消毒', NULL, 1, 70, '😷', NULL, '口罩、消毒、急救与防护耗材', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()),
('tcm_health', '中医保健', NULL, 1, 80, '🌿', NULL, '艾灸、贴敷、按摩理疗与草本养护', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()),
('home_care_daily', '居家护理', NULL, 1, 90, '🏠', NULL, '伤口、口腔、皮肤与家庭健康工具', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('all_medical', '全部', NULL, 1, 100, '🧺', NULL, '查看全部康养医疗商品', 'medical_mall', 'all', 'normal', TRUE, NOW(), NOW()),

('blood_pressure_monitor', '血压计', 'med_device', 2, 11, '🫀', NULL, '家庭血压监测设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()),
('blood_glucose_meter', '血糖仪', 'med_device', 2, 12, '🩸', NULL, '家庭血糖检测设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()),
('oximeter', '血氧仪', 'med_device', 2, 13, '💗', NULL, '指夹式血氧监测设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()),
('thermometer', '体温计', 'med_device', 2, 14, '🌡️', NULL, '额温枪与电子体温计', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()),
('oxygen_concentrator', '制氧机', 'med_device', 2, 15, '🫁', NULL, '家庭制氧与吸氧辅助设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()),
('nebulizer', '雾化器', 'med_device', 2, 16, '💨', NULL, '家用雾化护理设备', 'medical_mall', 'device', 'device_class_ii', TRUE, NOW(), NOW()),
('wheelchair_crutch', '轮椅拐杖', 'med_device', 2, 17, '🦽', NULL, '轮椅、拐杖与行动辅助器具', 'medical_mall', 'device', 'device_class_i', TRUE, NOW(), NOW()),
('nursing_bed', '护理床', 'med_device', 2, 18, '🛏️', NULL, '护理床与居家照护床具', 'medical_mall', 'device', 'device_class_i', TRUE, NOW(), NOW()),

('cold_fever', '感冒发烧', 'otc_medicine', 2, 21, '🤒', NULL, '感冒、退热与家庭常备药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()),
('cough_throat', '咳嗽咽喉', 'otc_medicine', 2, 22, '🗣️', NULL, '咳嗽、咽喉与润喉护理', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()),
('stomach_medicine', '肠胃用药', 'otc_medicine', 2, 23, '🥣', NULL, '肠胃调理与胃肠常备药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()),
('skin_external', '皮肤外用', 'otc_medicine', 2, 24, '🧴', NULL, '皮肤喷剂、软膏与外用护理', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()),
('eye_ear_nose', '眼耳口鼻', 'otc_medicine', 2, 25, '👁️', NULL, '眼耳鼻喉口腔常备用品', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()),
('pain_relief', '止痛用药', 'otc_medicine', 2, 26, '🩹', NULL, '止痛、舒缓与应急常备药', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()),
('trauma_sprain', '跌打损伤', 'otc_medicine', 2, 27, '🦴', NULL, '跌打扭伤与运动损伤护理', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()),
('child_medicine', '儿童用药', 'otc_medicine', 2, 28, '🧒', NULL, '儿童常备药与护理用品', 'medical_mall', 'otc', 'otc', TRUE, NOW(), NOW()),

('postop_rehab', '术后康复', 'rehab_care', 2, 31, '🩺', NULL, '术后恢复与支撑护理', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()),
('wound_dressing', '伤口敷料', 'rehab_care', 2, 32, '🩹', NULL, '敷料、纱布与换药护理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('brace_support', '护具支具', 'rehab_care', 2, 33, '🦵', NULL, '护腰、护膝与支撑固定用品', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()),
('rehab_training', '康复训练器', 'rehab_care', 2, 34, '🏋️', NULL, '康复训练与恢复辅助设备', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()),
('physiotherapy_hot', '理疗热敷', 'rehab_care', 2, 35, '🔥', NULL, '热敷理疗与家庭舒缓护理', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()),
('mobility_training', '行动训练', 'rehab_care', 2, 36, '🚶', NULL, '恢复行动能力的辅助训练用品', 'medical_mall', 'rehab', 'normal', TRUE, NOW(), NOW()),

('hypertension', '高血压管理', 'chronic_monitor', 2, 41, '❤️', NULL, '高血压居家管理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('diabetes', '糖尿病管理', 'chronic_monitor', 2, 42, '🩸', NULL, '血糖监测与糖尿病管理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('cardiovascular', '心脑血管', 'chronic_monitor', 2, 43, '🫀', NULL, '心脑血管健康管理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('respiratory_health', '呼吸健康', 'chronic_monitor', 2, 44, '🫁', NULL, '呼吸道护理与呼吸健康', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('weight_bodyfat', '体重体脂', 'chronic_monitor', 2, 45, '⚖️', NULL, '体重与体脂监测', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('home_testing', '家庭检测', 'chronic_monitor', 2, 46, '🧪', NULL, '家庭常用健康检测用品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),

('anti_slip', '防滑安全', 'elderly_aid', 2, 51, '🧱', NULL, '长者防滑与跌倒预防', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()),
('elderly_bathroom', '适老卫浴', 'elderly_aid', 2, 52, '🚿', NULL, '浴室扶手与适老卫浴辅助', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()),
('eating_aid', '助餐用品', 'elderly_aid', 2, 53, '🍽️', NULL, '适老助餐与餐具辅助', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()),
('bathing_aid', '助浴用品', 'elderly_aid', 2, 54, '🛁', NULL, '助浴椅与洗护辅助用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()),
('incontinence_care', '失禁护理', 'elderly_aid', 2, 55, '🧻', NULL, '长者失禁护理用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()),
('daily_living_aid', '生活辅助', 'elderly_aid', 2, 56, '🪑', NULL, '日常起居与生活辅助用品', 'medical_mall', 'elderly', 'normal', TRUE, NOW(), NOW()),

('vitamin', '维生素', 'nutrition_health', 2, 61, '🍊', NULL, '复合维生素与维 C 等营养补充', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()),
('calcium', '钙铁锌硒', 'nutrition_health', 2, 62, '🦴', NULL, '钙铁锌硒等基础营养', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()),
('protein', '蛋白营养', 'nutrition_health', 2, 63, '🥛', NULL, '蛋白粉与恢复期营养', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()),
('elderly_nutrition', '老人营养', 'nutrition_health', 2, 64, '👴', NULL, '适合长者的专用营养补充', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()),
('gut_health', '肠道益生菌', 'nutrition_health', 2, 65, '🦠', NULL, '益生菌与肠胃营养补充', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()),
('immune_support', '免疫支持', 'nutrition_health', 2, 66, '🛡️', NULL, '免疫支持与日常补给', 'medical_mall', 'nutrition', 'normal', TRUE, NOW(), NOW()),

('mask', '口罩', 'protection_disinfection', 2, 71, '😷', NULL, '日常口罩与防护耗材', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()),
('disinfectant', '消毒液', 'protection_disinfection', 2, 72, '🧴', NULL, '家庭与环境消毒用品', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()),
('alcohol_wipes', '酒精湿巾', 'protection_disinfection', 2, 73, '🧻', NULL, '酒精湿巾与便携消毒', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()),
('gloves', '手套', 'protection_disinfection', 2, 74, '🧤', NULL, '检查手套与护理手套', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()),
('first_aid', '急救包', 'protection_disinfection', 2, 75, '🧰', NULL, '家庭急救包与应急护理', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()),
('dressing_tools', '棉签纱布', 'protection_disinfection', 2, 76, '🧺', NULL, '棉签纱布与护理耗材', 'medical_mall', 'protection', 'normal', TRUE, NOW(), NOW()),

('moxibustion', '艾灸拔罐', 'tcm_health', 2, 81, '🔥', NULL, '艾灸、拔罐与温灸理疗', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()),
('herbal_drink', '养生茶饮', 'tcm_health', 2, 82, '🍵', NULL, '草本茶饮与养生冲饮', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()),
('tcm_patch', '中医贴敷', 'tcm_health', 2, 83, '🩹', NULL, '中医贴敷与草本热敷', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()),
('medicated_diet', '药膳滋补', 'tcm_health', 2, 84, '🥣', NULL, '药膳汤料与滋补调养', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()),
('massage_tools', '按摩理疗', 'tcm_health', 2, 85, '💆', NULL, '按摩仪、刮痧与理疗工具', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()),
('foot_bath', '泡脚养生', 'tcm_health', 2, 86, '🪣', NULL, '泡脚包与足浴理疗用品', 'medical_mall', 'tcm', 'normal', TRUE, NOW(), NOW()),

('wound_care', '伤口护理', 'home_care_daily', 2, 91, '🩹', NULL, '创面处理与换药护理', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('oral_care', '口腔护理', 'home_care_daily', 2, 92, '🦷', NULL, '口腔护理与清洁用品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('skin_care', '皮肤护理', 'home_care_daily', 2, 93, '🧴', NULL, '皮肤护理与修护用品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('cleaning_care', '清洁护理', 'home_care_daily', 2, 94, '🫧', NULL, '清洁护理与日常消耗品', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('nursing_consumables', '护理耗材', 'home_care_daily', 2, 95, '📦', NULL, '棉签、纱布、护理垫等耗材', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW()),
('home_health_tool', '家庭健康工具', 'home_care_daily', 2, 96, '🧰', NULL, '家庭健康小工具与辅具', 'medical_mall', 'care', 'normal', TRUE, NOW(), NOW())
ON CONFLICT (id) DO UPDATE SET
    name = EXCLUDED.name,
    parent_id = EXCLUDED.parent_id,
    level = EXCLUDED.level,
    sort_order = EXCLUDED.sort_order,
    icon = EXCLUDED.icon,
    image_url = EXCLUDED.image_url,
    description = EXCLUDED.description,
    scene = EXCLUDED.scene,
    category_type = EXCLUDED.category_type,
    compliance_type = EXCLUDED.compliance_type,
    is_active = EXCLUDED.is_active,
    deleted_at = NULL,
    updated_at = NOW();

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'blood_pressure_monitor', TRUE, 10, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%血压计%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'blood_glucose_meter', TRUE, 10, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%血糖仪%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'thermometer', TRUE, 10, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%体温计%' OR p.name ILIKE '%额温枪%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'oxygen_concentrator', TRUE, 10, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%制氧机%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'nebulizer', TRUE, 10, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%雾化器%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'mask', TRUE, 20, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%口罩%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'disinfectant', TRUE, 20, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%消毒%' OR p.name ILIKE '%酒精%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'wound_care', TRUE, 20, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%创可贴%' OR p.name ILIKE '%纱布%' OR p.name ILIKE '%敷料%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'wheelchair_crutch', TRUE, 20, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%轮椅%' OR p.name ILIKE '%拐杖%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'nursing_bed', TRUE, 20, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%护理床%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'calcium', TRUE, 30, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%钙片%' OR p.name ILIKE '%钙铁锌%' OR p.name ILIKE '%补钙%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'vitamin', TRUE, 30, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%维生素%' OR p.name ILIKE '%维C%' OR p.name ILIKE '%维D%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'protein', TRUE, 30, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%蛋白%' OR p.name ILIKE '%蛋白粉%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

INSERT INTO public.medical_mall_product_categories (product_id, category_id, is_primary, sort_order, created_at)
SELECT p.id, 'cold_fever', TRUE, 40, NOW()
FROM public.ml_products p
WHERE p.name ILIKE '%感冒%' OR p.name ILIKE '%退热%' OR p.name ILIKE '%发烧%'
ON CONFLICT (product_id, category_id) DO UPDATE SET is_primary = EXCLUDED.is_primary, sort_order = EXCLUDED.sort_order, deleted_at = NULL;

COMMIT;