<?php

namespace MintyPHP\Service\Settings;

use MintyPHP\Repository\Settings\SettingRepositoryInterface;

class SettingsMetadataGateway
{
    public function __construct(private readonly SettingRepositoryInterface $settingRepository)
    {
    }

    public function get(string $key): ?array
    {
        return $this->settingRepository->find($key);
    }

    public function getValue(string $key): ?string
    {
        return $this->settingRepository->getValue($key);
    }

    public function getInt(string $key): ?int
    {
        $value = $this->settingRepository->getValue($key);
        if ($value === null || $value === '') {
            return null;
        }

        return (int) $value;
    }

    public function set(string $key, ?string $value, ?string $description = null): bool
    {
        return $this->settingRepository->set($key, $value, $description);
    }
}
