<?php

namespace App\Data\Validation;

use Nette\Schema\Expect;
use Nette\Schema\Processor;
use Nette\Schema\Schema;
use Nette\Schema\ValidationException;

class NetteValidator extends Validator implements ValidatesArray
{
    private Processor $schemaProcessor;
    private Schema $schema;

    public function __construct(Processor $schemaProcessor, Schema $schema)
    {
        $this->schemaProcessor = $schemaProcessor;
        $this->schema = $schema;
    }

    public function validateArray(array $items): ValidationResult
    {
        try {
            $this->schemaProcessor->process($this->schema, $items);

            return $this->success();
        } catch (ValidationException $e) {
            return $this->error($e->getMessage());
        }
    }
}
