<?php

declare(strict_types=1);

namespace Ferienpass\CoreBundle\Tests\Cron;

use Contao\CoreBundle\Cron\Cron;
use Ferienpass\CoreBundle\Cron\NotifyOfferComplete;
use Ferienpass\CoreBundle\Repository\OfferRepositoryInterface;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Workflow\WorkflowInterface;

final class NotifyOfferCompleteTest extends TestCase
{
    public function testWebScopeReturnsEarly(): void
    {
        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects(self::never())->method('dispatch');

        $repo = new class implements OfferRepositoryInterface {
            public bool $queryBuilderCalled = false;

            public function createQueryBuilder(string $alias): never
            {
                $this->queryBuilderCalled = true;
                throw new \RuntimeException('Should not be called');
            }

            public function findByEditionAndStatus(\Ferienpass\CoreBundle\Entity\Edition $edition, string $status): array { return []; }
            public function countByEditionAndStatus(\Ferienpass\CoreBundle\Entity\Edition $edition, string $status): int { return 0; }
            public function findByAlias(string $alias): null { return null; }
            public function findByUuid(string|\Symfony\Component\Uid\Uuid $uuid): null { return null; }
            public function createCopy(\Ferienpass\CoreBundle\Entity\Offer\OfferInterface $original, bool $withdrawDates = false): \Ferienpass\CoreBundle\Entity\Offer\OfferInterface { throw new \RuntimeException(); }
            public function createVariant(\Ferienpass\CoreBundle\Entity\Offer\OfferInterface $original): \Ferienpass\CoreBundle\Entity\Offer\OfferInterface { throw new \RuntimeException(); }
            public function variantFields(): array { return []; }
            public function createNew() { throw new \RuntimeException(); }
            public function find(mixed $id): null { return null; }
            public function findAll(): array { return []; }
            public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array { return []; }
            public function findOneBy(array $criteria): null { return null; }
            public function getClassName(): string { return ''; }
        };

        $workflow = $this->createStub(WorkflowInterface::class);

        $cron = new NotifyOfferComplete($repo, $bus, $workflow);
        $cron(Cron::SCOPE_WEB);

        self::assertFalse($repo->queryBuilderCalled);
    }
}
