-- IOM Platform - Seed Data
USE BeezifiIOM;

-- Tenant
INSERT INTO tenants (id, name, slug, plan) VALUES
(1, 'Demo Company Pty Ltd', 'demo-company', 'pro');

-- Categories
INSERT INTO categories (id, tenant_id, name, parent_id) VALUES
(1, 1, 'Electronics', NULL),
(2, 1, 'Clothing', NULL),
(3, 1, 'Food & Beverage', NULL),
(4, 1, 'Smartphones', 1),
(5, 1, 'Laptops', 1),
(6, 1, 'T-Shirts', 2),
(7, 1, 'Jackets', 2);

-- Price Tiers
INSERT INTO price_tiers (id, tenant_id, name, discount_percent) VALUES
(1, 1, 'Retail', 0.00),
(2, 1, 'Wholesale', 15.00),
(3, 1, 'VIP', 25.00);

-- Warehouses
INSERT INTO warehouses (id, tenant_id, name, code, address, city, state, country, is_default) VALUES
(1, 1, 'Main Warehouse', 'MAIN', '123 Industrial Ave', 'Sydney', 'NSW', 'AU', TRUE),
(2, 1, 'Melbourne Depot', 'MEL', '456 Logistics Rd', 'Melbourne', 'VIC', 'AU', FALSE),
(3, 1, 'Brisbane Store', 'BNE', '789 Commerce St', 'Brisbane', 'QLD', 'AU', FALSE);

-- Products (10 products)
INSERT INTO products (id, tenant_id, category_id, name, sku, description, cost_price, base_price, weight, unit_of_measure) VALUES
(1, 1, 4, 'iPhone 15 Pro', 'IPHONE-15-PRO', 'Apple iPhone 15 Pro 256GB', 850.00, 1299.00, 0.187, 'unit'),
(2, 1, 4, 'Samsung Galaxy S24', 'SAMSUNG-S24', 'Samsung Galaxy S24 128GB', 600.00, 999.00, 0.167, 'unit'),
(3, 1, 5, 'MacBook Pro 14"', 'MBP-14-M3', 'Apple MacBook Pro 14" M3 chip', 1200.00, 2499.00, 1.610, 'unit'),
(4, 1, 5, 'Dell XPS 15', 'DELL-XPS-15', 'Dell XPS 15 Intel i7 16GB', 900.00, 1799.00, 1.860, 'unit'),
(5, 1, 6, 'Classic White Tee', 'TEE-WHITE-M', 'Premium cotton white t-shirt medium', 8.00, 29.99, 0.200, 'unit'),
(6, 1, 6, 'Classic Black Tee', 'TEE-BLACK-M', 'Premium cotton black t-shirt medium', 8.00, 29.99, 0.200, 'unit'),
(7, 1, 7, 'Winter Parka Jacket', 'JACKET-PARKA-L', 'Waterproof winter parka jacket large', 45.00, 149.99, 1.200, 'unit'),
(8, 1, 3, 'Organic Coffee Beans 1kg', 'COFFEE-ORG-1KG', 'Single origin organic arabica beans', 12.00, 34.99, 1.050, 'kg'),
(9, 1, 3, 'Green Tea Collection', 'TEA-GREEN-100G', 'Premium Japanese green tea 100g', 5.00, 19.99, 0.120, 'unit'),
(10, 1, 1, 'USB-C Hub 7-in-1', 'HUB-USBC-7IN1', 'Multi-port USB-C hub with HDMI 4K', 18.00, 59.99, 0.180, 'unit');

-- Inventory (stock per warehouse)
INSERT INTO inventory (tenant_id, product_id, variant_id, warehouse_id, quantity, reserved_quantity, reorder_level, reorder_quantity) VALUES
-- Main Warehouse
(1, 1, NULL, 1, 45, 5, 10, 20),
(1, 2, NULL, 1, 32, 3, 10, 20),
(1, 3, NULL, 1, 15, 2, 5, 10),
(1, 4, NULL, 1, 22, 1, 5, 10),
(1, 5, NULL, 1, 150, 20, 30, 50),
(1, 6, NULL, 1, 120, 15, 30, 50),
(1, 7, NULL, 1, 60, 5, 10, 20),
(1, 8, NULL, 1, 200, 10, 50, 100),
(1, 9, NULL, 1, 180, 8, 50, 100),
(1, 10, NULL, 1, 75, 3, 20, 30),
-- Melbourne Depot
(1, 1, NULL, 2, 20, 2, 5, 10),
(1, 2, NULL, 2, 15, 1, 5, 10),
(1, 3, NULL, 2, 8, 0, 3, 5),
(1, 5, NULL, 2, 80, 5, 20, 30),
(1, 8, NULL, 2, 100, 5, 25, 50),
(1, 10, NULL, 2, 40, 2, 10, 20),
-- Brisbane Store
(1, 1, NULL, 3, 10, 1, 5, 10),
(1, 5, NULL, 3, 50, 3, 15, 25),
(1, 9, NULL, 3, 90, 4, 25, 50);

-- Customers (5 customers)
INSERT INTO customers (id, tenant_id, name, email, phone, company, customer_type, price_tier_id) VALUES
(1, 1, 'Sarah Johnson', 'sarah.j@email.com', '+61 400 111 222', NULL, 'retail', 1),
(2, 1, 'TechCorp Australia', 'orders@techcorp.com.au', '+61 2 9000 1234', 'TechCorp Australia Pty Ltd', 'b2b', 2),
(3, 1, 'Mike Williams', 'mike.w@email.com', '+61 411 333 444', NULL, 'retail', 1),
(4, 1, 'Retail Giant Pty Ltd', 'procurement@retailgiant.com', '+61 3 8000 5678', 'Retail Giant Pty Ltd', 'wholesale', 2),
(5, 1, 'Emma Chen', 'emma.c@email.com', '+61 422 555 666', NULL, 'retail', 3);

-- Customer Addresses
INSERT INTO customer_addresses (customer_id, tenant_id, address_type, street, city, state, postcode, country, is_default) VALUES
(1, 1, 'shipping', '10 George St', 'Sydney', 'NSW', '2000', 'AU', TRUE),
(2, 1, 'billing', '50 Collins St', 'Melbourne', 'VIC', '3000', 'AU', TRUE),
(2, 1, 'shipping', '50 Collins St', 'Melbourne', 'VIC', '3000', 'AU', TRUE),
(3, 1, 'shipping', '25 Queen St', 'Brisbane', 'QLD', '4000', 'AU', TRUE),
(4, 1, 'billing', '100 Flinders St', 'Melbourne', 'VIC', '3001', 'AU', TRUE),
(5, 1, 'shipping', '7 Bay St', 'Sydney', 'NSW', '2060', 'AU', TRUE);

-- Suppliers
INSERT INTO suppliers (id, tenant_id, name, email, phone, contact_person, company, payment_terms) VALUES
(1, 1, 'Apple Australia', 'trade@apple.com.au', '+61 2 8080 8080', 'Trade Desk', 'Apple Pty Ltd', 'Net 30'),
(2, 1, 'Samsung Electronics', 'b2b@samsung.com.au', '+61 3 9000 9000', 'B2B Sales', 'Samsung Electronics AU', 'Net 30'),
(3, 1, 'Dell Technologies', 'channel@dell.com.au', '+61 2 7700 7700', 'Channel Team', 'Dell Australia Pty Ltd', 'Net 45'),
(4, 1, 'Garment Wholesale Co', 'orders@garmentwholesale.com.au', '+61 3 8800 8800', 'Alex Brown', 'Garment Wholesale Co', 'Net 14'),
(5, 1, 'Pacific Food Importers', 'buy@pacificfood.com.au', '+61 7 3300 3300', 'Supply Team', 'Pacific Food Importers', 'Net 30');

-- Orders (10 orders)
INSERT INTO orders (id, tenant_id, order_number, customer_id, status, channel, subtotal, tax_amount, shipping_amount, total_amount, cost_total, warehouse_id, created_by) VALUES
(1, 1, 'ORD-00001', 1, 'delivered', 'manual', 1299.00, 129.90, 0.00, 1428.90, 850.00, 1, 1),
(2, 1, 'ORD-00002', 2, 'shipped', 'b2b', 8995.00, 899.50, 0.00, 9894.50, 6000.00, 1, 1),
(3, 1, 'ORD-00003', 3, 'fulfilled', 'manual', 59.98, 5.998, 9.95, 75.928, 16.00, 1, 2),
(4, 1, 'ORD-00004', 4, 'paid', 'b2b', 14994.00, 1499.40, 0.00, 16493.40, 9000.00, 1, 1),
(5, 1, 'ORD-00005', 5, 'paid', 'online', 34.99, 3.499, 5.95, 44.439, 5.00, 1, NULL),
(6, 1, 'ORD-00006', 1, 'pending', 'manual', 2499.00, 249.90, 0.00, 2748.90, 1200.00, 1, 2),
(7, 1, 'ORD-00007', 3, 'pending', 'api', 149.99, 15.00, 9.95, 174.94, 45.00, 2, NULL),
(8, 1, 'ORD-00008', 5, 'pending', 'online', 119.97, 12.00, 0.00, 131.97, 24.00, 1, NULL),
(9, 1, 'ORD-00009', 2, 'fulfilling', 'b2b', 4995.00, 499.50, 0.00, 5494.50, 3000.00, 1, 1),
(10, 1, 'ORD-00010', 4, 'draft', 'manual', 2799.00, 280.00, 0.00, 3079.00, 1800.00, 1, 1);

-- Order Items
INSERT INTO order_items (order_id, tenant_id, product_id, quantity, fulfilled_quantity, unit_price, unit_cost, total_price) VALUES
(1, 1, 1, 1, 1, 1299.00, 850.00, 1299.00),
(2, 1, 1, 5, 5, 1299.00, 850.00, 6495.00),
(2, 1, 2, 3, 3, 833.33, 600.00, 2499.99),
(3, 1, 5, 1, 1, 29.99, 8.00, 29.99),
(3, 1, 6, 1, 1, 29.99, 8.00, 29.99),
(4, 1, 3, 6, 0, 2499.00, 1200.00, 14994.00),
(5, 1, 8, 1, 0, 34.99, 12.00, 34.99),
(6, 1, 3, 1, 0, 2499.00, 1200.00, 2499.00),
(7, 1, 7, 1, 0, 149.99, 45.00, 149.99),
(8, 1, 5, 2, 0, 29.99, 8.00, 59.98),
(8, 1, 9, 3, 0, 19.99, 5.00, 59.97),
(9, 1, 2, 5, 2, 999.00, 600.00, 4995.00),
(10, 1, 4, 1, 0, 1799.00, 900.00, 1799.00),
(10, 1, 3, 1, 0, 1000.00, 900.00, 1000.00);

-- Inventory Movements (sample movements)
INSERT INTO inventory_movements (tenant_id, product_id, warehouse_id, type, quantity, balance_after, reference_type, notes, created_by) VALUES
(1, 1, 1, 'receive', 50, 50, 'purchase_order', 'Initial stock receipt', 1),
(1, 1, 1, 'ship', -5, 45, 'order', 'Order ORD-00001 and ORD-00002', 1),
(1, 2, 1, 'receive', 35, 35, 'purchase_order', 'Initial stock receipt', 1),
(1, 2, 1, 'ship', -3, 32, 'order', 'Order ORD-00002', 1),
(1, 5, 1, 'receive', 200, 200, 'purchase_order', 'Garment restock', 1),
(1, 5, 1, 'ship', -50, 150, 'order', 'Various orders', 1),
(1, 8, 1, 'receive', 250, 250, 'purchase_order', 'Coffee stock', 1),
(1, 8, 1, 'ship', -50, 200, 'order', 'Various orders', 1);
