<?php
namespace Bookaro\Repository;

defined( 'ABSPATH' ) || exit;

class OptionRepository extends AbstractRepository
{
    public const OPTION_KEY = 'bookaro_settings';

    /**
     * Retrieve all plugin options.
     */
    public function get_all(): array
    {
        $options = get_option(self::OPTION_KEY, []);
        return is_array($options) ? $options : [];
    }

    /**
     * Get a single option value.
     *
     * @param string $key     Option key.
     * @param mixed  $default Default value if not set.
     * @return mixed
     */
    public function get(string $key, $default = null)
    {
        $options = $this->get_all();
        return $options[$key] ?? $default;
    }

    /**
     * Update all plugin options at once.
     */
    public function update(array $settings): bool
    {
        return update_option(self::OPTION_KEY, $settings);
    }
}

