<?php

namespace ModulesGarden\Servers\ZimbraEmail\App\Libs\Restrictions\Interfaces;


use ModulesGarden\Servers\ZimbraEmail\App\Libs\Restrictions\Restriction;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 07.11.19
 * Time: 10:29
 * Class AbstractRestriction
 */
abstract class AbstractRestriction
{
    const STATUS_VALID      = true;
    const STATUS_INVALID    = false;

    /**
     * @var bool
     */
    protected $throwError = false;

    /**
     * @var RuleInterface
     */
    protected $rule;

    /**
     * @var
     */
    public $errorMessage;

    /**
     * @var bool
     */
    public $isValid = self::STATUS_VALID;

    /**
     * Restriction constructor.
     * @param RuleInterface $rule
     */
    public function __construct(RuleInterface $rule)
    {
        $this->rule = $rule;
    }

    /**
     *
     * check restriction
     * @return mixed
     */
    public abstract function check();

    /**
     * @return bool
     */
    public function isThrowErrorEnabled()
    {
        return $this->throwError === true;
    }

    /**
     * @return $this
     */
    public function enableThrowError()
    {
        $this->throwError = true;
        return $this;
    }

    /**
     * @return $this
     */
    public function disableThrowError()
    {
        $this->throwError = true;
        return $this;
    }

    /**
     * @return RuleInterface
     */
    public function getRule()
    {
        return $this->rule;
    }

    /**
     * @param RuleInterface $rule
     */
    public function setRule(RuleInterface $rule)
    {
        $this->rule = $rule;
    }

    /**
     * @return mixed
     */
    public function getErrorMessage()
    {
        return $this->errorMessage;
    }

    /**
     * @param mixed $errorMessage
     */
    public function setErrorMessage($errorMessage)
    {
        $this->errorMessage = $errorMessage;
    }

    /**
     * @return bool
     */
    public function isValid()
    {
        return $this->isValid;
    }

    /**
     * @param bool $isValid
     */
    public function setIsValid($isValid)
    {
        $this->isValid = $isValid;
    }
}