<?php

namespace Build\Validators;

use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Validation;

final class ProjectsListValidator
{
    use \ValidatesRequests;

    /**
     * @param array $requestData
     * @throws \InvalidArgumentException
     * @return void
     */
    public static function validateListRequest(array $requestData)
    {
        $validator = Validation::createValidator();
        $constraints = new Assert\Collection(
            fields: [
                'is_deployed_locally' => new Assert\Optional([
                    new Assert\Choice(choices: ['true', 'false'])
                ]),
                'is_local' => new Assert\Optional([
                    new Assert\Choice(choices: ['true', 'false'])
                ]),
                'name' => new Assert\Optional([
                    new Assert\Type(type: 'string')
                ]),
                'limit' => new Assert\Optional([
                    new Assert\Type(type: 'numeric'),
                    new Assert\Range(min: 0, max: 100)
                ]),
                'skip' => new Assert\Optional([
                    new Assert\Type(type: 'numeric'),
                    new Assert\PositiveOrZero()
                ])
            ]
        );

        self::throwOnIssues($validator->validate($requestData, $constraints));
    }
}
