<?php

it('syncs lane relay states when department self-serve enabled flag changes', function (): void {
    $routeContent = file_get_contents(app_path('routes/departmentsRoute.php'));

    expect($routeContent)->not->toBeFalse();
    expect($routeContent)->toContain('/departments/self-serve/enabled');
    expect($routeContent)->toContain('$this->syncDepartmentSelfServeRelayStates((int)$department->id, $enabled);');
    expect($routeContent)->toContain('if (!$enabled) {');
    expect($routeContent)->toContain('// Self-serve disabled: restore normal/manual relay operation.');
    expect($routeContent)->toContain('setMachineProgramPickerRelayStatusHard(true)');
    expect($routeContent)->toContain('setMachineRelayStatusHard(true)');
    expect($routeContent)->toContain('!$department_lane->isSelfServeEnabled()');
    expect($routeContent)->toContain('setMachineProgramPickerRelayStatus(false)');
    expect($routeContent)->toContain('setMachineCleanerRelayStatusHard(true)');
    expect($routeContent)->toContain('setMachineRelayStatus(false)');
    expect($routeContent)->not->toContain('setMachineProgramPickerRelayStatusHard(false)');
    expect($routeContent)->not->toContain('setMachineCleanerRelayStatusHard(false)');
    expect($routeContent)->not->toContain('setMachineRelayStatusHard(false)');
    expect($routeContent)->not->toContain('setMachineCleanerRelayStatus(false)');
});
