-- =============================================================
-- 测试门店 S002 种子数据（空库存版）
-- 用法: sh scripts/dev.sh seed S002
-- 说明: 仅写入数据，不清空。加 --clear 参数先清空再写入
-- 模拟新门店初始状态，无历史入库/出库/库存数据
-- =============================================================

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ── 门店 ────────────────────────────────────────────────────
INSERT IGNORE INTO shops (name, code, address, phone, manager_name, created_at, updated_at)
VALUES ('醇香汇酒业', 'S002', '上海市静安区南京西路1288号恒隆广场L1-06', '021-52088899', '李文博', NOW(), NOW());

SET @shop_id = (SELECT id FROM shops WHERE code = 'S002' LIMIT 1);

-- ── 用户（密码均为 password123）────────────────────────────
SET @pwd = '$2a$10$BNHhJoKHryCCEyKqM.11TeLOnSCV8rNtOqvKHUqaczETXLtH/YE1m';

INSERT INTO users (shop_id, username, password_hash, real_name, phone, role, is_active, created_at, updated_at)
VALUES
  (@shop_id, 'admin',    @pwd, '李文博（管理员）', '13900000001', 'admin',    1, NOW(), NOW()),
  (@shop_id, 'operator', @pwd, '陈小红（操作员）', '13900000002', 'operator', 1, NOW(), NOW()),
  (@shop_id, 'test',     @pwd, '王明（只读）',     '13900000003', 'readonly', 1, NOW(), NOW())
ON DUPLICATE KEY UPDATE password_hash = @pwd, is_active = 1, updated_at = NOW();

-- ── 仓库 ────────────────────────────────────────────────────
INSERT IGNORE INTO warehouses (shop_id, name, location, is_default, created_at, updated_at) VALUES
(@shop_id, '主仓库',     'A区1层',       1, NOW(), NOW()),
(@shop_id, '进口酒专库', 'B区恒温展示区', 0, NOW(), NOW());

-- ── 商品分类 ────────────────────────────────────────────────
INSERT IGNORE INTO product_categories (shop_id, name, sort_order, created_at, updated_at) VALUES
(@shop_id, '白酒',   1, NOW(), NOW()),
(@shop_id, '进口烈酒', 2, NOW(), NOW());

-- ── 商品 ────────────────────────────────────────────────────
SET @cat_baijiu  = (SELECT id FROM product_categories WHERE shop_id = @shop_id AND name = '白酒'   LIMIT 1);
SET @cat_import  = (SELECT id FROM product_categories WHERE shop_id = @shop_id AND name = '进口烈酒' LIMIT 1);

INSERT IGNORE INTO products (shop_id, public_id, code, barcode, name, series, spec, unit, category_id, brand,
                      purchase_price, sale_price, min_stock, remark, created_at, updated_at) VALUES
(@shop_id, 'b2c3d4e5-0002-0002-0002-000000000001', 'MT-001',  '6901234567890', '飞天茅台 53度',  '茅台',     '500ml/瓶', '瓶', @cat_baijiu, '贵州茅台',       2350, 2800, 10, '酱香型白酒，53度，飞天系列', NOW(), NOW()),
(@shop_id, 'b2c3d4e5-0002-0002-0002-000000000002', 'WLY-001', '6902345678901', '五粮液 52度',    '五粮液',   '500ml/瓶', '瓶', @cat_baijiu, '宜宾五粮液',     950,  1200, 6,  '浓香型白酒，52度，普五系列', NOW(), NOW()),
(@shop_id, 'b2c3d4e5-0002-0002-0002-000000000003', 'YH-001',  '6903456789012', '洋河梦之蓝 M6',  '洋河',     '500ml/瓶', '瓶', @cat_baijiu, '江苏洋河',       560,  680,  6,  '浓香型，绵柔苏酒代表',       NOW(), NOW()),
(@shop_id, 'b2c3d4e5-0002-0002-0002-000000000004', 'LZ-001',  '6904567890123', '泸州老窖 特曲',  '泸州老窖', '500ml/瓶', '瓶', @cat_baijiu, '泸州老窖',       420,  520,  6,  '浓香鼻祖，特曲系列',         NOW(), NOW()),
(@shop_id, 'b2c3d4e5-0002-0002-0002-000000000005', 'JNC-001', '6905678901234', '剑南春 水晶剑',  '剑南春',   '500ml/瓶', '瓶', @cat_baijiu, '剑南春',         390,  480,  6,  '浓香型，绵竹名酒',           NOW(), NOW()),
(@shop_id, 'b2c3d4e5-0002-0002-0002-000000000006', 'LJ-001',  '6906789012345', '郎酒 红花郎10',  '郎酒',     '500ml/瓶', '瓶', @cat_baijiu, '古蔺郎酒',       320,  420,  6,  '酱香型，赤水河畔酿造',       NOW(), NOW()),
(@shop_id, 'b2c3d4e5-0002-0002-0002-000000000007', 'LF-001',  '3760093550058', '拉菲古堡 2018',  '波尔多',   '750ml/瓶', '瓶', @cat_import, 'Château Lafite', 3800, 5200, 3,  '波尔多一级名庄，2018年份',   NOW(), NOW()),
(@shop_id, 'b2c3d4e5-0002-0002-0002-000000000008', 'RTM-001', '3021691010008', '人头马 VSOP',    '人头马',   '700ml/瓶', '瓶', @cat_import, 'Rémy Martin',    480,  680,  3,  '法国干邑，VSOP级别',         NOW(), NOW());

-- ── 往来单位 ────────────────────────────────────────────────
INSERT IGNORE INTO partners (shop_id, code, name, type, contact, phone, address, bank_account,
                      credit_limit, balance, remark, created_at, updated_at) VALUES
(@shop_id, 'SUP001', '贵州茅台酒股份有限公司',   'supplier', '张经理', '0851-22222001', '贵州省仁怀市茅台镇',         '工商银行仁怀支行 6222 0000 0001 0001', 5000000, 0, '茅台系列直供，账期30天', NOW(), NOW()),
(@shop_id, 'SUP002', '四川五粮液股份有限公司',   'supplier', '王总监', '0831-33333001', '四川省宜宾市翠屏区',         '建设银行宜宾支行 6227 0000 0001 0002', 3000000, 0, '五粮液系列授权经销',     NOW(), NOW()),
(@shop_id, 'SUP003', '江苏洋河酒厂股份有限公司', 'supplier', '赵主任', '0527-44444001', '江苏省宿迁市洋河新区',       '农业银行宿迁支行 6228 0000 0001 0003', 2000000, 0, '洋河梦之蓝系列直供',     NOW(), NOW()),
(@shop_id, 'SUP004', '四川郎酒股份有限公司',     'supplier', '刘经理', '0830-55555001', '四川省古蔺县二郎镇',         '中国银行古蔺支行 6013 0000 0001 0004', 1500000, 0, '郎酒红花郎系列',         NOW(), NOW()),
(@shop_id, 'CUS001', '上海外滩五号餐厅',         'customer', '林采购', '021-63869001',  '上海市黄浦区外滩5号',         '浦发银行上海黄浦支行 6210 0000 0003 0001', 300000, 0, '高端餐厅，月结',         NOW(), NOW()),
(@shop_id, 'CUS002', '苏州虎丘山庄度假酒店',     'customer', '周总', '0512-66888001',   '江苏省苏州市虎丘区虎丘路168号', '工商银行苏州支行 6222 0000 0003 0002', 200000, 0, '度假酒店，季结',         NOW(), NOW());

-- ── 编号规则（序号从 0 开始，无历史单据）──────────────────
INSERT IGNORE INTO number_rules (shop_id, type, prefix, current_no, date_format, updated_at) VALUES
(@shop_id, 'stock_in',        'RK', 0, 'YYYYMMDD', NOW()),
(@shop_id, 'stock_out',       'CK', 0, 'YYYYMMDD', NOW()),
(@shop_id, 'inventory_check', 'PD', 0, 'YYYYMMDD', NOW());

-- ── 入库单/出库单/库存/流水/财务：均为空 ──────────────────
-- 模拟新门店初始状态，无历史数据

SET FOREIGN_KEY_CHECKS = 1;
