-- Seed Data for Affiliate Program
-- Run this after schema.sql

-- ----------------------------
-- Default Program Configuration
-- ----------------------------
INSERT INTO `program_config` (`config_key`, `config_value`, `description`) VALUES
('total_payout_percent', '60', 'Total percentage of subscription paid out to affiliates'),
('levels_paid', '5', 'Number of upline levels that receive commissions'),
('company_name', 'TradePro Affiliates', 'Company/program name'),
('currency', 'USD', 'Default currency'),
('min_payout', '50', 'Minimum payout threshold in USD'),
('payout_day', '15', 'Day of month payouts are processed');

-- ----------------------------
-- Default Commission Splits (5 levels = 60% total)
-- ----------------------------
INSERT INTO `commission_splits` (`level`, `percent`, `is_active`) VALUES
(1, 25.00, 1),
(2, 15.00, 1),
(3, 10.00, 1),
(4, 6.00, 1),
(5, 4.00, 1);

-- ----------------------------
-- Admin User
-- Password: admin123 (change immediately in production!)
-- ----------------------------
INSERT INTO `users` (`email`, `password_hash`, `role`, `first_name`, `last_name`, `is_active`) VALUES
('admin@tradepro.com', '$2y$12$7GSrQ/Kn5WUGS7cHRQWYGeS89yssY78eYC.wwxhEgpmsFpvZMDhdm', 'admin', 'System', 'Admin', 1);

-- ----------------------------
-- Sample Affiliate Users with Sponsor Chain
-- Password for all: password123
--
-- Structure:
-- Alice (no sponsor - top of tree)
--   └── Bob (sponsored by Alice)
--       └── Charlie (sponsored by Bob)
--           └── Diana (sponsored by Charlie)
--               └── Eve (sponsored by Diana)
-- ----------------------------

-- Alice - Top affiliate (no sponsor)
INSERT INTO `users` (`email`, `password_hash`, `role`, `first_name`, `last_name`, `is_active`) VALUES
('alice@example.com', '$2y$12$8qpXysL/zaMQWKXBqsEgy.2Qo4.GuKpnLbCnG6xHQIf529/oMAEiW', 'affiliate', 'Alice', 'Anderson', 1);

INSERT INTO `affiliate_profiles` (`user_id`, `sponsor_user_id`, `referral_code`) VALUES
((SELECT id FROM users WHERE email = 'alice@example.com'), NULL, 'ALICE001');

-- Bob - Sponsored by Alice
INSERT INTO `users` (`email`, `password_hash`, `role`, `first_name`, `last_name`, `is_active`) VALUES
('bob@example.com', '$2y$12$8qpXysL/zaMQWKXBqsEgy.2Qo4.GuKpnLbCnG6xHQIf529/oMAEiW', 'affiliate', 'Bob', 'Baker', 1);

INSERT INTO `affiliate_profiles` (`user_id`, `sponsor_user_id`, `referral_code`) VALUES
((SELECT id FROM users WHERE email = 'bob@example.com'),
 (SELECT id FROM users WHERE email = 'alice@example.com'),
 'BOB002');

-- Charlie - Sponsored by Bob
INSERT INTO `users` (`email`, `password_hash`, `role`, `first_name`, `last_name`, `is_active`) VALUES
('charlie@example.com', '$2y$12$8qpXysL/zaMQWKXBqsEgy.2Qo4.GuKpnLbCnG6xHQIf529/oMAEiW', 'affiliate', 'Charlie', 'Chen', 1);

INSERT INTO `affiliate_profiles` (`user_id`, `sponsor_user_id`, `referral_code`) VALUES
((SELECT id FROM users WHERE email = 'charlie@example.com'),
 (SELECT id FROM users WHERE email = 'bob@example.com'),
 'CHARLIE003');

-- Diana - Sponsored by Charlie
INSERT INTO `users` (`email`, `password_hash`, `role`, `first_name`, `last_name`, `is_active`) VALUES
('diana@example.com', '$2y$12$8qpXysL/zaMQWKXBqsEgy.2Qo4.GuKpnLbCnG6xHQIf529/oMAEiW', 'affiliate', 'Diana', 'Davis', 1);

INSERT INTO `affiliate_profiles` (`user_id`, `sponsor_user_id`, `referral_code`) VALUES
((SELECT id FROM users WHERE email = 'diana@example.com'),
 (SELECT id FROM users WHERE email = 'charlie@example.com'),
 'DIANA004');

-- Eve - Sponsored by Diana
INSERT INTO `users` (`email`, `password_hash`, `role`, `first_name`, `last_name`, `is_active`) VALUES
('eve@example.com', '$2y$12$8qpXysL/zaMQWKXBqsEgy.2Qo4.GuKpnLbCnG6xHQIf529/oMAEiW', 'affiliate', 'Eve', 'Edwards', 1);

INSERT INTO `affiliate_profiles` (`user_id`, `sponsor_user_id`, `referral_code`) VALUES
((SELECT id FROM users WHERE email = 'eve@example.com'),
 (SELECT id FROM users WHERE email = 'diana@example.com'),
 'EVE005');

-- ----------------------------
-- Sample Activity Log Entry
-- ----------------------------
INSERT INTO `activity_log` (`user_id`, `action`, `description`) VALUES
((SELECT id FROM users WHERE email = 'admin@tradepro.com'), 'system_init', 'Database initialized with seed data');
