-- =========================================================================
-- MIGRATION: Tetapan Sistem Sejagat (Fasa Kesinambungan — Set 1)
-- Jalankan di phpMyAdmin > tab SQL, pada database SPMS sedia ada anda.
--
-- Jadual generik key-value untuk tetapan operasi (berasingan daripada
-- login_page_settings yang khusus untuk branding). Merangkumi:
--   - Ambang Risk Monitoring (dahulu keras-kod 70/90 di 2 fail berasingan)
--   - Had masa sesi (session timeout)
-- =========================================================================

CREATE TABLE IF NOT EXISTS system_settings (
    setting_key     VARCHAR(100) PRIMARY KEY,
    setting_value   TEXT NOT NULL,
    updated_at      DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
    updated_by      CHAR(36) NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO system_settings (setting_key, setting_value) VALUES
    ('risk_threshold_red', '70'),
    ('risk_threshold_amber', '90'),
    ('session_timeout_minutes', '30')
ON DUPLICATE KEY UPDATE setting_key = setting_key;
