<?php

namespace Modules\Setting\Services;

use Illuminate\Http\Request;
use Modules\Setting\Models\Setting;
use Modules\Setting\Interfaces\SettingRepositoryInterface;

class SettingService
{
    private SettingRepositoryInterface $settingRepository ;

    public function __construct(SettingRepositoryInterface $settingRepository)
    {
        $this->settingRepository = $settingRepository;
    }

    public function get(Request $request)
    {
        $settings= $this->settingRepository->get($request);

        if(count($settings) > 0){
            foreach ($settings as $setting) {
                $settings->{$setting['key']} = $setting['value'];
            }
        } else {
            $settings = null;
        }

        return $settings;
    }
    public function save(Request $request):void
    {
        $this->settingRepository->save($request);
    }
    public function modules(Request $request):void
    {
        $this->settingRepository->modules($request);
    }
}
