<?php

declare(strict_types=1);

namespace CpCreation\VitiCore\Tests\Monitoring\External;

use CpCreation\VitiCore\Monitoring\External\ExternalConnectionHealthReporter;
use CpCreation\VitiCore\Monitoring\External\Message\DeliverExternalConnectionHealthMessage;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\MessageBusInterface;

final class ExternalConnectionHealthReporterTest extends TestCase
{
    public function testItReportsOnlyStateChangesDuringOneRequest(): void
    {
        $bus = $this->createMock(MessageBusInterface::class);
        $bus->expects(self::exactly(2))
            ->method('dispatch')
            ->with(self::isInstanceOf(DeliverExternalConnectionHealthMessage::class))
            ->willReturnCallback(static fn (object $message): Envelope => new Envelope($message));
        $reporter = new ExternalConnectionHealthReporter($bus);

        $reporter->report('brevo', true, 120);
        $reporter->report('brevo', true, 100);
        $reporter->report('brevo', false, 300, 'Erreur');
        $reporter->report('brevo', false, 250, 'Erreur');
    }
}
