-- SMTP Configuration Table
-- Stores email server settings for license delivery and notifications

CREATE TABLE IF NOT EXISTS smtp_config (
    id INT AUTO_INCREMENT PRIMARY KEY,
    host VARCHAR(255) NOT NULL,
    port INT NOT NULL DEFAULT 587,
    username VARCHAR(255) NOT NULL,
    password TEXT NOT NULL, -- Should be encrypted in production
    encryption ENUM('tls', 'ssl', 'none') DEFAULT 'tls',
    from_email VARCHAR(255) NOT NULL,
    from_name VARCHAR(255) NOT NULL DEFAULT 'CmdSharp',
    active BOOLEAN DEFAULT 1,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    INDEX idx_active (active),
    INDEX idx_created_at (created_at)
);

-- Insert default SMTP configuration
INSERT INTO smtp_config (
    host, port, username, password, encryption, 
    from_email, from_name, active
) VALUES (
    '', 587, '', '', 'tls',
    'support@proviska.com', 'CmdSharp', 0
) ON DUPLICATE KEY UPDATE id=id;
