<?php

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


use function ModulesGarden\Servers\ZimbraEmail\Core\Helper\di;
use ModulesGarden\Servers\ZimbraEmail\Core\Lang\Lang;

/**
 *
 * Created by PhpStorm.
 * User: Tomasz Bielecki ( tomasz.bi@modulesgarden.com )
 * Date: 07.11.19
 * Time: 10:02
 * Class AbstractRule
 */
abstract class AbstractRule implements RuleInterface
{

    /**
     * @var string
     */
    protected $message = 'somethingWentWrong';

    /**
     * @var array
     */
    protected $replacements = [];

    /**
     * @param $key
     * @param $value
     * @return $this
     */
    protected function addReplacement($key, $value)
    {
        $this->replacements[$key] = $value;
        return $this;
    }
    /**
     *
     * @return mixed|void
     */
    public function getMessage()
    {
        /* @var $lang Lang*/
        $lang = di('lang');

        foreach($this->replacements as $key => $repl)
        {
            $lang->addReplacementConstant($key, $repl);
        }

        return $lang->absoluteT('restrictions', 'error', $this->message);
    }

}