-- =========================================================================
-- MIGRATION: Notifikasi E-mel & 2FA (Fasa Kesinambungan — Set 3)
-- Jalankan di phpMyAdmin > tab SQL, pada database SPMS sedia ada anda.
-- =========================================================================

-- Tetapan e-mel & 2FA (guna jadual system_settings sedia ada)
INSERT INTO system_settings (setting_key, setting_value) VALUES
    ('email_notifications_enabled', '0'),
    ('smtp_host', ''),
    ('smtp_port', '587'),
    ('smtp_username', ''),
    ('smtp_password', ''),
    ('smtp_encryption', 'tls'),
    ('smtp_from_email', ''),
    ('smtp_from_name', 'SPMS'),
    ('notify_recipients', ''),
    ('two_factor_enabled', '0')
ON DUPLICATE KEY UPDATE setting_key = setting_key;

-- Kolum 2FA untuk setiap pengguna
ALTER TABLE app_users
    ADD COLUMN totp_secret VARCHAR(32) NULL AFTER password_hash,
    ADD COLUMN totp_confirmed TINYINT(1) NOT NULL DEFAULT 0 AFTER totp_secret;
