<?php

namespace AC_SYNC\Includes\Classes\Setting {
  if (!defined('ABSPATH')) exit; // Exit if accessed directly
  class Action_Wear_Setting_Log_Writing implements Action_Wear_Setting_Entity
  {

    const OPTION_NAME = '_ACTIONWEAR_LOG_WRITING';

    public function toggle()
    {
      return $this->set(!$this->get());
    }

    public function get()
    {
      return get_option(self::OPTION_NAME, true) ? true : false;
    }

    public function validate($v): bool
    {
      return is_bool($v);
    }

    public function set($value)
    {
      if (!$this->validate($value)) throw new \Exception("Only boolean values are accepted to this setting");
      update_option(self::OPTION_NAME, $value ? 1 : 0);
      return $this->get();
    }
  }
}
