<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Tests\Scheduler;

use CpCreation\VitiCore\Bridge\Symfony\Bundle\Scheduler\PurgeExpiredRegistrationsMessage;
use CpCreation\VitiCore\Bridge\Symfony\Bundle\Scheduler\VitiCoreSchedule;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Scheduler\Generator\MessageContext;
use Symfony\Contracts\Cache\CacheInterface;

final class VitiCoreScheduleTest extends TestCase
{
    public function testItSchedulesTheExpiredRegistrationPurgeEveryDay(): void
    {
        $schedule = new VitiCoreSchedule($this->createMock(CacheInterface::class))->getSchedule();
        $matchingTriggers = [];

        foreach ($schedule->getRecurringMessages() as $recurringMessage) {
            $context = new MessageContext(
                'test',
                $recurringMessage->getId(),
                $recurringMessage->getTrigger(),
                new \DateTimeImmutable('2026-08-27 12:00:00'),
            );

            foreach ($recurringMessage->getMessages($context) as $message) {
                if ($message instanceof PurgeExpiredRegistrationsMessage) {
                    $matchingTriggers[] = (string) $recurringMessage->getTrigger();
                }
            }
        }

        self::assertSame(['every 1 day'], $matchingTriggers);
    }
}
