-- CY.CASH DEVELOPMENT SANDBOX DATA
-- Run ONLY inside your separate development database (for example fcaglobal_dev).
-- Do NOT run this against the live GoldCoders database.

START TRANSACTION;

-- Clean only this dedicated test account if it already exists.
SET @test_user_id := (SELECT id FROM hm2_users WHERE username='testuser' LIMIT 1);
DELETE FROM hm2_user_notices WHERE user_id=@test_user_id AND @test_user_id IS NOT NULL;
DELETE FROM hm2_history WHERE user_id=@test_user_id AND @test_user_id IS NOT NULL;
DELETE FROM hm2_deposits WHERE user_id=@test_user_id AND @test_user_id IS NOT NULL;
DELETE FROM hm2_user_balances WHERE user_id=@test_user_id AND @test_user_id IS NOT NULL;
DELETE FROM cy_auth_security WHERE user_id=@test_user_id AND @test_user_id IS NOT NULL;
DELETE FROM cy_audit_log WHERE user_id=@test_user_id AND @test_user_id IS NOT NULL;
DELETE FROM cy_sessions WHERE user_id=@test_user_id AND @test_user_id IS NOT NULL;
DELETE FROM hm2_users WHERE username='testuser';

-- Development investment definitions. IDs are explicit so the test deposits can reference them.
DELETE FROM hm2_types WHERE id IN (9001,9002,9003);
DELETE FROM hm2_plans WHERE id IN (9001,9002,9003);

INSERT INTO hm2_types
(id,name,description,q_days,min_deposit,max_deposit,period,status,return_profit,return_profit_percent,percent,parent,ordering,allow_internal_deps,allow_external_deps)
VALUES
(9001,'Prime Reserve','Development sandbox position',1,100.0000000000,2000.0000000000,'Hours','on','1',100.00,6.00,0,1,1,1),
(9002,'Quantum Select','Development sandbox position',1,2001.0000000000,10000.0000000000,'Hours','on','1',100.00,8.00,0,2,1,1),
(9003,'Apex Private','Development sandbox position',1,10001.0000000000,100000.0000000000,'Hours','on','1',100.00,12.00,0,3,1,1);

INSERT INTO hm2_plans (id,name,description,min_deposit,max_deposit,percent,status,parent,ext_id,bonus_percent,fiat)
VALUES
(9001,'Prime Reserve','Premium sandbox plan for interface testing.',100.0000000000,2000.0000000000,6.00,'on',0,9001,0.00,'USD'),
(9002,'Quantum Select','Premium sandbox plan for interface testing.',2001.0000000000,10000.0000000000,8.00,'on',0,9002,0.00,'USD'),
(9003,'Apex Private','Premium sandbox plan for interface testing.',10001.0000000000,100000.0000000000,12.00,'on',0,9003,0.00,'USD');

INSERT INTO hm2_users
(name,username,password,date_register,email,status,ref,deposit_total,confirm_string,password_confimation,ip_reg,last_access_time,last_access_ip,stat_password,auto_withdraw,user_auto_pay_earning,admin_auto_pay_earning,pswd,hid,l_e_t,activation_code,bf_counter,address,city,state,zip,country,transaction_code,ac,accounts,sq,sa,reg_fee,home_phone,cell_phone,work_phone,verify,pax_utype,gfst_phone,add_fields,admin_desc,max_daily_withdraw,group_id,tfa_flag,demo_acc,mult,mult_last_check)
VALUES
('CY Test User','testuser',MD5('Test1234'),DATE_SUB(NOW(),INTERVAL 8 MONTH),'test@cy.cash','on',0,20000.0000000000,'','','',DATE_SUB(NOW(),INTERVAL 2 HOUR),'127.0.0.1','',1,0,0,'','','2004-01-01 00:00:00','',0,'','','','','United Kingdom','','','','','',0.0000000000,'','','',1,0,'','','Development sandbox account',0.0000000000,0,0,1,0,NULL);

SET @uid := LAST_INSERT_ID();

-- Active positions. Existing GoldCoders triggers populate active_deposit balances automatically.
INSERT INTO hm2_deposits
(user_id,type_id,deposit_date,last_pay_date,status,q_pays,amount,actual_amount,ec,compound,dde,unit_amount,bonus_flag,init_amount)
VALUES
(@uid,9001,DATE_SUB(NOW(),INTERVAL 9 DAY),DATE_SUB(NOW(),INTERVAL 1 DAY),'on',0,1500.0000000000,1500.0000000000,0,0.00,'1999-01-01 00:00:00',1.0000000000,0,1500.0000000000),
(@uid,9002,DATE_SUB(NOW(),INTERVAL 6 DAY),DATE_SUB(NOW(),INTERVAL 1 DAY),'on',0,3000.0000000000,3000.0000000000,0,0.00,'1999-01-01 00:00:00',1.0000000000,0,3000.0000000000),
(@uid,9003,DATE_SUB(NOW(),INTERVAL 3 DAY),DATE_SUB(NOW(),INTERVAL 1 DAY),'on',0,3000.0000000000,3000.0000000000,0,0.00,'1999-01-01 00:00:00',1.0000000000,0,3000.0000000000);

-- Ledger entries. Existing history triggers populate the general 'balance' bucket and per-type buckets.
-- Net available balance after these entries = 12,480.50.
INSERT INTO hm2_history (user_id,amount,type,description,actual_amount,date,str,ec,deposit_id,confirm_delete,hidden_batch,rate,batch,stype) VALUES
(@uid,20000.0000000000,'deposit','Development funding credited',20000.0000000000,DATE_SUB(NOW(),INTERVAL 24 DAY),'',0,0,'','',1.0000000000,'DEV-FUND-001',NULL),
(@uid,-1500.0000000000,'investment','Capital allocated to Prime Reserve',-1500.0000000000,DATE_SUB(NOW(),INTERVAL 9 DAY),'',0,0,'','',1.0000000000,'DEV-INV-001',NULL),
(@uid,-3000.0000000000,'investment','Capital allocated to Quantum Select',-3000.0000000000,DATE_SUB(NOW(),INTERVAL 6 DAY),'',0,0,'','',1.0000000000,'DEV-INV-002',NULL),
(@uid,450.5000000000,'earning','Sandbox earnings credit',450.5000000000,DATE_SUB(NOW(),INTERVAL 5 DAY),'',0,0,'','',1.0000000000,'DEV-EARN-001',NULL),
(@uid,230.0000000000,'referral_commission','Sandbox referral reward',230.0000000000,DATE_SUB(NOW(),INTERVAL 4 DAY),'',0,0,'','',1.0000000000,'DEV-REF-001',NULL),
(@uid,-3000.0000000000,'investment','Capital allocated to Apex Private',-3000.0000000000,DATE_SUB(NOW(),INTERVAL 3 DAY),'',0,0,'','',1.0000000000,'DEV-INV-003',NULL),
(@uid,800.0000000000,'earning','Sandbox earnings credit',800.0000000000,DATE_SUB(NOW(),INTERVAL 2 DAY),'',0,0,'','',1.0000000000,'DEV-EARN-002',NULL),
(@uid,-1500.0000000000,'withdrawal','Sandbox withdrawal processed',-1500.0000000000,DATE_SUB(NOW(),INTERVAL 1 DAY),'',0,0,'','',1.0000000000,'DEV-WD-001',NULL);

INSERT INTO hm2_user_notices (user_id,date,expiration,text,title,notified) VALUES
(@uid,NOW(),0,'Your development workspace has been upgraded with the new premium dashboard experience.','Premium workspace enabled',0),
(@uid,DATE_SUB(NOW(),INTERVAL 1 DAY),0,'Two-factor authentication is available in the Security Center.','Security recommendation',0);

COMMIT;

-- Verification output
SELECT id,username,email,status FROM hm2_users WHERE id=@uid;
SELECT type,ROUND(SUM(amount),2) AS amount FROM hm2_user_balances WHERE user_id=@uid GROUP BY type ORDER BY type;
SELECT ROUND(SUM(actual_amount),2) AS active_capital FROM hm2_deposits WHERE user_id=@uid AND status='on';
