<?php

namespace Tests\Support;

use App\Contracts\PendingNotificationProcessor;
use Mtc\MercuryDataModels\Vehicle;

/**
 * Test double for ProcessPendingProviderNotifications: records the payloads it is
 * handed and whether auditing was suppressed at the moment it ran.
 */
class RecordingPendingProcessor implements PendingNotificationProcessor
{
    /** @var array<int, array> */
    public static array $received = [];

    /** @var array<int, bool> */
    public static array $auditingDisabled = [];

    public static bool $throwNext = false;

    public static function reset(): void
    {
        self::$received = [];
        self::$auditingDisabled = [];
        self::$throwNext = false;
    }

    public function process(array $payload): void
    {
        self::$auditingDisabled[] = Vehicle::isAuditingDisabled();

        if (self::$throwNext) {
            self::$throwNext = false;
            throw new \RuntimeException('forced failure');
        }

        self::$received[] = $payload;
    }
}
