<?php

namespace Application\Service\Extension\Validator;

class BaseCustomValidator
{
    protected $message;

    public array $attributeLabels = [];

    public function __construct(array $config = [])
    {
        foreach ($config as $key => $value) {
            if (property_exists($this, $key)) {
                $this->{$key} = $value;
            }
        }
    }

    public function isValid($value, $attribute)
    {
        return true;
    }

    public function formatMessage($message, $params)
    {
        $placeholders = [];
        foreach ((array) $params as $name => $value) {
            $placeholders['{' . $name . '}'] = $value;
        }

        return ($placeholders === []) ? $message : strtr($message, $placeholders);
    }


    public function getAttributeLabel(string $field)
    {
        return $this->attributeLabels[$field] ?? $field;
    }
}