<?php

declare(strict_types=1);

namespace PpPhp\Core\Platform\Services\Descriptor;

final class DescriptorValidator
{
    /**
     * @return string[]
     */
    public function validate(ServiceDescriptor $descriptor): array
    {
        $errors = [];

        if ($descriptor->id() === '') {
            $errors[] = 'Service descriptor id is required.';
        }

        if ($descriptor->label() === '') {
            $errors[] = 'Service descriptor label is required.';
        }

        if ($descriptor->version() === '') {
            $errors[] = 'Service descriptor version is required.';
        }

        if (!in_array($descriptor->lifecycle(), ['singleton', 'transient'], true)) {
            $errors[] = 'Service descriptor lifecycle must be singleton or transient.';
        }

        if (!in_array($descriptor->visibility(), ['public', 'internal', 'private'], true)) {
            $errors[] = 'Service descriptor visibility must be public, internal or private.';
        }

        return $errors;
    }
}
