<?php
namespace Dreamfox\DeliveryDate\Premium\Repositories;

use Dreamfox\DeliveryDate\Interfaces\RepositoryInterface;
use Dreamfox\DeliveryDate\Premium\OtherSetting;
use stdClass;

class OtherSettingRepository implements RepositoryInterface
{

  const KEY_REQUIRED = 'dreamfox_wdd_premium_required';
  const KEY_SHOW_EMPTY = 'dreamfox_wdd_premium_showEmptyOnCheckout';
  const KEY_LABEL = 'dreamfox_wdd_premium_labelOnCheckout';
  const KEY_DESCRIPTION = 'dreamfox_wdd_premium_descriptionOnCheckout';

  public function save($item)
  {
    update_option(self::KEY_REQUIRED, $item->getRequired());
    update_option(self::KEY_SHOW_EMPTY, $item->getShowEmptyOnCheckout());
    update_option(self::KEY_LABEL, $item->getLabelOnCheckout());
    update_option(self::KEY_DESCRIPTION, $item->getDescriptionOnCheckout());
  }

  public function load()
  {
    $data = new stdClass();
    $data->required = get_option(self::KEY_REQUIRED, false);
    $data->showEmptyOnCheckout = get_option(self::KEY_SHOW_EMPTY, false);
    $data->labelOnCheckout = get_option(self::KEY_LABEL, 'Select delivery date');
    $data->descriptionOnCheckout = get_option(self::KEY_DESCRIPTION, 'We will try our best to deliver your order on the specified date');
    $settings = new OtherSetting($data);
    return $settings;
  }
}