<?php

declare(strict_types=1);

namespace app\models;

class Requisite extends Document
{
    public static function collectionName(): string
    {
        return 'requisite';
    }

    public function attributes(): array
    {
        return array_merge(
            parent::attributes(),
            ['name', 'value']
        );
    }

    public function rules(): array
    {
        return array_merge(
            parent::rules(),
            [
                [
                    ['name', 'value'],
                    'required',
                    'message' => 'Заполните поле: {attribute}'
                ]
            ]
        );
    }

    public function attributeLabels(): array
    {
        return array_merge(
            parent::attributeLabels(),
            [
                'name' => 'Название',
                'value' => 'Значение'
            ]
        );
    }

    public static function readByName(string $name)
    {
        return static::findOne(['name' => $name]);
    }
}
