CREATE TABLE IF NOT EXISTS user_balances (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    symbol VARCHAR(10) NOT NULL,
    available DECIMAL(20, 8) DEFAULT 0,
    frozen DECIMAL(20, 8) DEFAULT 0,
    UNIQUE KEY (user_id, symbol)
) ENGINE=InnoDB;

CREATE TABLE IF NOT EXISTS transactions (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    type VARCHAR(20) NOT NULL,
    amount DECIMAL(20, 8) NOT NULL,
    symbol VARCHAR(10) NOT NULL,
    status VARCHAR(20) DEFAULT 'completed',
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB;

-- Insert a default user balance for testing (assuming user_id 1)
INSERT IGNORE INTO user_balances (user_id, symbol, available) VALUES (1, 'USDT', 0.00);
