CREATE TABLE IF NOT EXISTS smtp_settings (
    id INT AUTO_INCREMENT PRIMARY KEY,
    transport VARCHAR(20) DEFAULT 'smtp',
    smtp_host VARCHAR(255),
    smtp_port INT DEFAULT 587,
    smtp_secure VARCHAR(10) DEFAULT 'tls',
    smtp_user VARCHAR(255),
    smtp_pass VARCHAR(255),
    from_email VARCHAR(255),
    from_name VARCHAR(255),
    reply_to VARCHAR(255),
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

-- Insert default row if not exists
INSERT INTO smtp_settings (id, transport, smtp_host, smtp_port, smtp_secure, from_email, from_name)
SELECT 1, 'smtp', '', 587, 'tls', 'no-reply@localhost', 'App'
WHERE NOT EXISTS (SELECT 1 FROM smtp_settings WHERE id = 1);
