<?php

it('wires self-serve machine signals through the broker control plane', function (): void {
    $routeSource = (string)file_get_contents(app_path('routes/edgeGatewaysRoute.php'));
    $agentSource = (string)file_get_contents(app_path('resources/edge-gateway-agent/agent.php'));
    $machineSignalSource = (string)file_get_contents(app_path('modules/selfserve/classes/selfserve_machine_signal.php'));

    expect($routeSource)->toContain("'/edge-agent/internal/gateways/{id}/selfserve/machine-signal'")
        ->and($routeSource)->toContain('private function handleBrokerSelfserveMachineSignal(): void')
        ->and($routeSource)->toContain('recordBrokerEdgeGatewaySignal($gatewayId, $payload)')
        ->and($agentSource)->toContain("'type' => 'MACHINE_SIGNAL'")
        ->and($agentSource)->toContain('#/edge-agent/gateways/\d+/selfserve/machine-signal$#')
        ->and($machineSignalSource)->toContain('public function recordBrokerEdgeGatewaySignal(int $gatewayId, array $payload): array')
        ->and($machineSignalSource)->toContain('private function recordEdgeGatewaySignalForDepartment(int $gatewayId, int $departmentId, array $payload): array');
});
