<?php

namespace MintyPHP\Tests\Service\Scheduler;

use MintyPHP\Repository\Scheduler\ScheduledJobRepository;
use MintyPHP\Repository\Scheduler\ScheduledJobRunRepository;
use MintyPHP\Repository\Scheduler\SchedulerRuntimeRepository;
use MintyPHP\Service\Scheduler\ScheduleCalculator;
use MintyPHP\Service\Scheduler\ScheduledJobRegistry;
use MintyPHP\Service\Scheduler\ScheduledJobService;
use MintyPHP\Service\Scheduler\SchedulerRunService;
use PHPUnit\Framework\TestCase;

class SchedulerRunServiceTest extends TestCase
{
    public function testRunJobNowRejectsInvalidRequest(): void
    {
        $scheduledJobService = $this->createMock(ScheduledJobService::class);
        $scheduledJobService->expects($this->once())->method('ensureSystemJobs');

        $service = new SchedulerRunService(
            $scheduledJobService,
            $this->createMock(ScheduledJobRepository::class),
            $this->createMock(ScheduledJobRunRepository::class),
            $this->createMock(SchedulerRuntimeRepository::class),
            $this->createMock(ScheduledJobRegistry::class),
            new ScheduleCalculator()
        );

        $result = $service->runJobNow(0, 0);

        $this->assertFalse($result['ok']);
        $this->assertSame('invalid_request', $result['error']);
    }
}
