-- Admin Core: system-wide settings kept separate from business shop_settings.
CREATE TABLE IF NOT EXISTS system_settings (
    id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    setting_key VARCHAR(100) NOT NULL,
    setting_value VARCHAR(255) NOT NULL,
    setting_type ENUM('boolean', 'integer', 'string') NOT NULL DEFAULT 'string',
    updated_by BIGINT UNSIGNED NULL,
    updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
        ON UPDATE CURRENT_TIMESTAMP,
    UNIQUE KEY uq_system_settings_key (setting_key),
    CONSTRAINT fk_system_settings_updated_by
        FOREIGN KEY (updated_by) REFERENCES users(id)
        ON DELETE SET NULL,
    INDEX idx_system_settings_updated_by (updated_by)
) ENGINE=InnoDB;

INSERT INTO system_settings (
    setting_key,
    setting_value,
    setting_type
)
VALUES
    ('registration_enabled', '1', 'boolean'),
    ('maintenance_mode', '0', 'boolean'),
    ('activity_logging_enabled', '1', 'boolean'),
    ('max_upload_mb', '5', 'integer')
ON DUPLICATE KEY UPDATE setting_key = VALUES(setting_key);
