<?php
    namespace App\Utils;

    class SettingsHelperItem {
        public string $setting;
        public string $type;

        function __construct(string $setting, string $type) {
            $this->setting = $setting;
            $this->type = $type;
        }
    }

    class SettingsHelper {

        private array $settings = []; 
        function __construct() {
            
            $this->settings[] = new SettingsHelperItem("whoarewe",              "html");
            $this->settings[] = new SettingsHelperItem("whoarewe-sponsored-by", "html");
            $this->settings[] = new SettingsHelperItem("legal",                 "html");
            $this->settings[] = new SettingsHelperItem("www-subtitle",          "txt");
            $this->settings[] = new SettingsHelperItem("seo-keywords",          "txt");
            $this->settings[] = new SettingsHelperItem("seo-description",       "txt");
        }

        public function exists(string $setting) : string {
            return !empty(array_filter($this->settings, function ( $sett ) use ($setting) {
                return $sett->setting == $setting;
            }));
        }

        public function checkExistance(string $setting) : void {
            if (!$this->exists($setting)) {
                throw new \Exception("Le paramètre demandé n'existe pas : $setting - pour le rajouter App\Utils\SettingsHelper");
            }
        }

        public function getType(string $setting) : string {
            $res = array_filter($this->settings, function ( $sett ) use ($setting) {
                if ($sett->setting == $setting) return $sett;
            });
            if (count($res) != 1) throw new \Exception("Erreur lors de la récuparation du setting $setting");
            // dd($res);
            return array_pop($res)->type;
        }

        public function getAll(): array {
            return $this->settings;
        }
    }