<?php
declare(strict_types=1);

class Setting {
    private Database $db;

    public function __construct() {
        $this->db = new Database();
    }

    // Safely Upsert setting (Insert if it doesn't exist, Update if it does)
    public function updateSetting(string $key, string $value): bool {
        $this->db->query('INSERT INTO settings (setting_key, setting_value) VALUES (:key, :value) ON DUPLICATE KEY UPDATE setting_value = :value_update');
        $this->db->bind(':key', $key);
        $this->db->bind(':value', $value);
        $this->db->bind(':value_update', $value);
        
        return $this->db->execute();
    }
}