<?php

namespace Openguru\OpenCartFramework\Scheduler;

use Openguru\OpenCartFramework\Container\Container;

class ScheduleJobRegistry
{
    private Container $container;

    /** @var Job[] */
    private array $jobs = [];

    public function __construct(Container $container)
    {
        $this->container = $container;
    }

    /**
     * @param string|callable|TaskInterface $job
     * @param string|null $name
     * @return Job
     */
    public function add($job, ?string $name = null): Job
    {
        $newJob = new Job($this->container, $job, $name);
        $this->jobs[] = $newJob;

        return $newJob;
    }

    /**
     * @return Job[]
     */
    public function getJobs(): array
    {
        return $this->jobs;
    }
}
