-- Add missing fields for Profile, KYC and Security
ALTER TABLE users 
ADD COLUMN total_recharge DECIMAL(16,4) DEFAULT 0,
ADD COLUMN transaction_password VARCHAR(255) DEFAULT NULL,
ADD COLUMN kyc_name VARCHAR(100) DEFAULT NULL,
ADD COLUMN kyc_id_number VARCHAR(50) DEFAULT NULL,
ADD COLUMN kyc_photo_front VARCHAR(255) DEFAULT NULL,
ADD COLUMN kyc_photo_back VARCHAR(255) DEFAULT NULL,
ADD COLUMN kyc_photo_handheld VARCHAR(255) DEFAULT NULL,
ADD COLUMN kyc_status INT DEFAULT 0 COMMENT '0: Unverified, 1: Pending, 2: Verified, 3: Rejected';

-- Update credit_score default
ALTER TABLE users MODIFY COLUMN credit_score INT DEFAULT 80;

-- Ensure existing users have a credit score and UID if missing
UPDATE users SET credit_score = 80 WHERE credit_score IS NULL;
UPDATE users SET uid = LPAD(FLOOR(RAND() * 100000000), 8, '0') WHERE uid IS NULL OR uid = '';
