<?php

namespace App\Controller\Commands;

use Closure;

/**
 *
 */
class Command
{
    public function __construct(
        private readonly string $name,
        private readonly Closure $callback,
        private readonly array  $mandatoryParameters = [],
        private readonly array  $optionalParameters = [],
        private readonly string $description = ''
    )
    {
        // no body
    }


    /**
     * @return string
     */
    public function getName(): string
    {
        return $this->name;
    }

    /**
     * @return array
     */
    public function getMandatoryParameters(): array
    {
        return $this->mandatoryParameters;
    }

    /**
     * @return array
     */
    public function getOptionalParameters(): array
    {
        return $this->optionalParameters;
    }

    /**
     * @return string|null
     */
    public function getDescription(): ?string
    {
        return $this->description;
    }

    /**
     * @return Closure
     */
    public function getCallback(): Closure
    {
        return $this->callback;
    }

    public function exec(): void
    {
        call_user_func(callback: $this->callback);
    }
}