-- Migration: User and System Updates
-- Adds UID, KYC fields, and system configuration tables

ALTER TABLE users ADD COLUMN IF NOT EXISTS uid INT(6) ZEROFILL UNIQUE AFTER id;
ALTER TABLE users ADD COLUMN IF NOT EXISTS real_name VARCHAR(100) AFTER username;
ALTER TABLE users ADD COLUMN IF NOT EXISTS id_number VARCHAR(50) AFTER real_name;
ALTER TABLE users ADD COLUMN IF NOT EXISTS id_front VARCHAR(255) AFTER id_number;
ALTER TABLE users ADD COLUMN IF NOT EXISTS id_back VARCHAR(255) AFTER id_front;
ALTER TABLE users ADD COLUMN IF NOT EXISTS id_handheld VARCHAR(255) AFTER id_back;
ALTER TABLE users ADD COLUMN IF NOT EXISTS kyc_status ENUM('none', 'pending', 'approved', 'rejected') DEFAULT 'none' AFTER id_handheld;
ALTER TABLE users ADD COLUMN IF NOT EXISTS security_password VARCHAR(255) AFTER password_hash;

CREATE TABLE IF NOT EXISTS system_config (
    id INT AUTO_INCREMENT PRIMARY KEY,
    config_key VARCHAR(100) UNIQUE,
    config_value TEXT
);

CREATE TABLE IF NOT EXISTS translations (
    id INT AUTO_INCREMENT PRIMARY KEY,
    lang_code VARCHAR(10),
    trans_key VARCHAR(100),
    trans_value TEXT,
    UNIQUE KEY (lang_code, trans_key)
);

INSERT IGNORE INTO system_config (config_key, config_value) VALUES ('win_loss_rate', '50');
INSERT IGNORE INTO system_config (config_key, config_value) VALUES ('price_control_mode', 'market');
INSERT IGNORE INTO system_config (config_key, config_value) VALUES ('site_name', 'BITCrypto');
