

-- =========================
-- TELEGRAM CHANNELS
-- =========================
CREATE TABLE telegram_channels (
    id INT AUTO_INCREMENT PRIMARY KEY,
    channel_name VARCHAR(255),
    channel_id VARCHAR(100),
    active TINYINT(1) DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- =========================
-- SIGNALS
-- =========================
CREATE TABLE signals (
    id INT AUTO_INCREMENT PRIMARY KEY,
    message_id BIGINT,
    channel_id VARCHAR(100),
    symbol VARCHAR(20),
    direction VARCHAR(10),
    entry_from DECIMAL(10,2),
    entry_to DECIMAL(10,2),
    stop_loss DECIMAL(10,2),
    tp1 DECIMAL(10,2),
    tp2 DECIMAL(10,2),
    tp3 DECIMAL(10,2),
    raw_signal LONGTEXT,
    status VARCHAR(30) DEFAULT 'Pending',
    received_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- =========================
-- TRADES
-- =========================
CREATE TABLE trades (
    id INT AUTO_INCREMENT PRIMARY KEY,
    signal_id INT,
    ticket BIGINT,
    symbol VARCHAR(20),
    direction VARCHAR(10),
    lot DECIMAL(10,2),
    open_price DECIMAL(10,5),
    close_price DECIMAL(10,5),
    stop_loss DECIMAL(10,5),
    take_profit DECIMAL(10,5),
    profit DECIMAL(12,2),
    status VARCHAR(30),
    opened_at DATETIME,
    closed_at DATETIME,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY(signal_id) REFERENCES signals(id)
);

-- =========================
-- SETTINGS
-- =========================
CREATE TABLE settings (
    id INT AUTO_INCREMENT PRIMARY KEY,
    setting_key VARCHAR(100),
    setting_value TEXT
);

-- =========================
-- LOGS
-- =========================
CREATE TABLE logs (
    id INT AUTO_INCREMENT PRIMARY KEY,
    level VARCHAR(20),
    message TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);