const mysql = require('mysql2/promise');


const pool = mysql.createPool({
    host: '192.168.1.6',
    user: 'bot',
    password: 'NxKr63LJB65pHv%t7E$JqgxKRsZMw%VIHEZAjq%^O0KYKjW#cRc^ebIH@%S9kaTh*GIg^D3ai4KBjMeXEh6xwv#9afQIR2$!2UB8C3ToXjnYFmzR%$lfpshnf8g@8229',
    database: 'bot',
    waitForConnections: true,
    connectionLimit: 10,
    queueLimit: 0
});

async function initDB() {
    const conn = await pool.getConnection();
    try {
        await conn.query(`
            CREATE TABLE IF NOT EXISTS bans (
                                                userId VARCHAR(32) PRIMARY KEY,
                reason TEXT,
                modId VARCHAR(32),
                timestamp BIGINT,
                type VARCHAR(20) NOT NULL,
                unbanDate BIGINT
                )
        `);

        await conn.query(`
            CREATE TABLE IF NOT EXISTS logs (
                                                id INT AUTO_INCREMENT PRIMARY KEY,
                                                userId VARCHAR(32),
                userTag VARCHAR(100),
                modId VARCHAR(32),
                modTag VARCHAR(100),
                action VARCHAR(20),
                reason TEXT,
                type ENUM('Permanent','Temporary') DEFAULT 'Permanent',
                timestamp BIGINT
                )
        `);
    } finally {
        conn.release();
    }
}

initDB().catch(console.error);

module.exports = pool;
