-- MediFlash SOS+ Sample Data
-- Test users, pharmacies, couriers, and medicines

-- Insert test users
INSERT INTO users (id, role, name, phone, email, password_hash, lat, lng, address, active) VALUES
-- Admin user
('admin-001', 'admin', 'Admin MediFlash', '+225 27 20 00 00', 'admin@mediflash.local', '$2y$12$rQvKzMPdQMBwNUq7UfXSZOBmYpPmIqJk5OyYhMVqRvFwVfXsQoGd6', NULL, NULL, 'Siège MediFlash, Plateau', TRUE),

-- Test client
('client-001', 'client', 'Jean Kouassi', '+225 07 12 34 56', 'client@mediflash.local', '$2y$12$rQvKzMPdQMBwNUq7UfXSZOBmYpPmIqJk5OyYhMVqRvFwVfXsQoGd6', 5.3364, -4.0267, 'Cocody, Riviera Golf', TRUE),

-- Test pharmacies
('pharm-001', 'pharmacy', 'Dr. Marie Koffi', '+225 27 22 11 11', 'pharm1@mediflash.local', '$2y$12$rQvKzMPdQMBwNUq7UfXSZOBmYpPmIqJk5OyYhMVqRvFwVfXsQoGd6', 5.3197, -4.0297, 'Plateau, Abidjan', TRUE),
('pharm-002', 'pharmacy', 'Dr. Paul Kouame', '+225 27 22 22 22', 'pharm2@mediflash.local', '$2y$12$rQvKzMPdQMBwNUq7UfXSZOBmYpPmIqJk5OyYhMVqRvFwVfXsQoGd6', 5.3444, -4.0556, 'Adjamé, Abidjan', TRUE),

-- Test couriers
('courier-001', 'courier', 'Koffi Yao', '+225 07 11 22 33', 'courier1@mediflash.local', '$2y$12$rQvKzMPdQMBwNUq7UfXSZOBmYpPmIqJk5OyYhMVqRvFwVfXsQoGd6', 5.3300, -4.0300, 'Plateau, Abidjan', TRUE),
('courier-002', 'courier', 'Adjoua Assoumou', '+225 07 22 33 44', 'courier2@mediflash.local', '$2y$12$rQvKzMPdQMBwNUq7UfXSZOBmYpPmIqJk5OyYhMVqRvFwVfXsQoGd6', 5.3400, -4.0400, 'Cocody, Abidjan', TRUE),
('courier-003', 'courier', 'Ibrahim Traore', '+225 07 33 44 55', 'courier3@mediflash.local', '$2y$12$rQvKzMPdQMBwNUq7UfXSZOBmYpPmIqJk5OyYhMVqRvFwVfXsQoGd6', 5.3500, -4.0500, 'Yopougon, Abidjan', TRUE);

-- Insert pharmacies
INSERT INTO pharmacies (id, user_id, name, lat, lng, address, verified) VALUES
('pharmacy-001', 'pharm-001', 'Pharmacie Centrale', 5.3197, -4.0297, 'Boulevard de la République, Plateau, Abidjan', TRUE),
('pharmacy-002', 'pharm-002', 'Pharmacie du Nord', 5.3444, -4.0556, 'Marché d\'Adjamé, Adjamé, Abidjan', TRUE);

-- Insert couriers
INSERT INTO couriers (id, user_id, vehicle_type, lat, lng, active, available) VALUES
('courier-profile-001', 'courier-001', 'motorcycle', 5.3300, -4.0300, TRUE, TRUE),
('courier-profile-002', 'courier-002', 'motorcycle', 5.3400, -4.0400, TRUE, TRUE),
('courier-profile-003', 'courier-003', 'scooter', 5.3500, -4.0500, TRUE, FALSE);

-- Insert common medicines
INSERT INTO medicines (id, name, atc_code) VALUES
('med-001', 'Paracétamol 500mg', 'N02BE01'),
('med-002', 'Aspirine 500mg', 'N02BA01'),
('med-003', 'Ibuprofène 400mg', 'M01AE01'),
('med-004', 'Doliprane 1000mg', 'N02BE01'),
('med-005', 'Efferalgan 500mg', 'N02BE01'),
('med-006', 'Spasfon', 'A03AB'),
('med-007', 'Amoxicilline 500mg', 'J01CA04'),
('med-008', 'Flagyl 500mg', 'P01AB01'),
('med-009', 'Voltarène 50mg', 'M01AB05'),
('med-010', 'Tramadol 50mg', 'N02AX02');

-- Insert pharmacy stock
INSERT INTO pharmacy_stock (pharmacy_id, medicine_id, stock, unit_price) VALUES
-- Pharmacie Centrale stock
('pharmacy-001', 'med-001', 50, 80000), -- Paracétamol 800 FCFA
('pharmacy-001', 'med-002', 30, 60000), -- Aspirine 600 FCFA
('pharmacy-001', 'med-003', 25, 120000), -- Ibuprofène 1200 FCFA
('pharmacy-001', 'med-004', 40, 100000), -- Doliprane 1000 FCFA
('pharmacy-001', 'med-005', 35, 90000), -- Efferalgan 900 FCFA
('pharmacy-001', 'med-006', 20, 150000), -- Spasfon 1500 FCFA
('pharmacy-001', 'med-007', 15, 200000), -- Amoxicilline 2000 FCFA
('pharmacy-001', 'med-008', 12, 180000), -- Flagyl 1800 FCFA
('pharmacy-001', 'med-009', 18, 250000), -- Voltarène 2500 FCFA
('pharmacy-001', 'med-010', 10, 300000), -- Tramadol 3000 FCFA

-- Pharmacie du Nord stock
('pharmacy-002', 'med-001', 60, 75000), -- Paracétamol 750 FCFA
('pharmacy-002', 'med-002', 40, 55000), -- Aspirine 550 FCFA
('pharmacy-002', 'med-003', 30, 110000), -- Ibuprofène 1100 FCFA
('pharmacy-002', 'med-004', 35, 95000), -- Doliprane 950 FCFA
('pharmacy-002', 'med-005', 25, 85000), -- Efferalgan 850 FCFA
('pharmacy-002', 'med-006', 15, 140000), -- Spasfon 1400 FCFA
('pharmacy-002', 'med-007', 20, 190000), -- Amoxicilline 1900 FCFA
('pharmacy-002', 'med-008', 8, 170000), -- Flagyl 1700 FCFA
('pharmacy-002', 'med-009', 22, 240000), -- Voltarène 2400 FCFA
('pharmacy-002', 'med-010', 5, 290000); -- Tramadol 2900 FCFA

-- Create wallets for pharmacies and couriers
INSERT INTO wallets (owner_type, owner_id, balance) VALUES
('PHARMACY', 'pharmacy-001', 4560000), -- 45,600 FCFA
('PHARMACY', 'pharmacy-002', 3240000), -- 32,400 FCFA
('COURIER', 'courier-profile-001', 2350000), -- 23,500 FCFA
('COURIER', 'courier-profile-002', 1890000), -- 18,900 FCFA
('COURIER', 'courier-profile-003', 1120000); -- 11,200 FCFA

-- Insert a sample completed order for demonstration
INSERT INTO orders (id, client_id, pharmacy_id, courier_id, medicine_id, medicine_name, qty, med_price_total, service_fee, delivery_fee, distance_km, status, client_lat, client_lng, client_address, client_phone) VALUES
('order-001', 'client-001', 'pharmacy-001', 'courier-profile-001', 'med-001', 'Paracétamol 500mg', 2, 160000, 50000, 68000, 1.8, 'DELIVERED', 5.3364, -4.0267, 'Cocody, Riviera Golf', '+225 07 12 34 56');

-- Insert order events for the sample order
INSERT INTO order_events (order_id, event, meta) VALUES
('order-001', 'ORDER_CREATED', '{"client_phone": "+225 07 12 34 56", "medicine": "Paracétamol 500mg"}'),
('order-001', 'PHARMACY_CONFIRMED', '{"pharmacy": "Pharmacie Centrale", "unit_price": 800}'),
('order-001', 'COURIER_ASSIGNED', '{"courier": "Koffi Yao", "vehicle": "motorcycle"}'),
('order-001', 'PICKED_UP', '{"pickup_time": "2024-01-15T16:15:00"}'),
('order-001', 'DELIVERED', '{"delivery_time": "2024-01-15T16:35:00", "duration_minutes": 20}');

-- Insert ledger entries for the completed order
INSERT INTO ledger (order_id, entry_type, account, amount, note) VALUES
('order-001', 'CREDIT', 'MEDIFLASH', 50000, 'Frais de service'),
('order-001', 'CREDIT', 'PHARMACY', 170000, 'Paiement médicament (160000) + bonus (10000)'),
('order-001', 'CREDIT', 'COURIER', 58000, 'Frais de livraison (68000) - bonus pharmacie (10000)');

-- Update MediFlash wallet with earnings
UPDATE wallets SET balance = 62350000 WHERE owner_type = 'MEDIFLASH' AND owner_id IS NULL;

-- Add some recent activity for demonstration
INSERT INTO orders (id, client_id, pharmacy_id, medicine_id, medicine_name, qty, status, client_lat, client_lng, client_address, client_phone) VALUES
('order-002', 'client-001', 'pharmacy-002', 'med-004', 'Doliprane 1000mg', 1, 'PHARMACY_CONFIRMED', 5.3364, -4.0267, 'Cocody, Riviera Golf', '+225 07 12 34 56');

INSERT INTO order_events (order_id, event, meta) VALUES
('order-002', 'ORDER_CREATED', '{"client_phone": "+225 07 12 34 56", "medicine": "Doliprane 1000mg"}'),
('order-002', 'PHARMACY_CONFIRMED', '{"pharmacy": "Pharmacie du Nord", "unit_price": 950}');
