<?php

it('stores wash_started_at in self-serve wash sessions when machine start is triggered', function (): void {
    $sessionsObject = file_get_contents(app_path('objects/selfserve_wash_sessions_o.php'));

    expect($sessionsObject)->not->toBeFalse();
    expect($sessionsObject)->toContain('public object_property $wash_started_at;');
    expect($sessionsObject)->toContain("\$this->wash_started_at = new object_property(");
    expect($sessionsObject)->toContain("\$this->wash_started_at->set(\$resolvedWashStartedAt);");
    expect($sessionsObject)->toContain("'wash_started_at' =>");
});

it('passes lane wash start time into the session machine-start marker', function (): void {
    $washFlow = file_get_contents(app_path('modules/selfserve/classes/selfserve_wash_flow.php'));

    expect($washFlow)->not->toBeFalse();
    expect($washFlow)->toContain('$washStartedAt = (int)$lane->getWashStartTime();');
    expect($washFlow)->toContain('$session->markMachineStartTriggered(');
    expect($washFlow)->toContain("date('Y-m-d H:i:s', \$washStartedAt)");
});

it('resolves in-progress wash_started_at from session with compatibility fallbacks', function (): void {
    $moduleSelfServeRoute = file_get_contents(app_path('routes/moduleSelfServeRoute.php'));

    expect($moduleSelfServeRoute)->not->toBeFalse();
    expect($moduleSelfServeRoute)->toContain('$wash_started_at = $session->wash_started_at->value() === null ? null : (string)$session->wash_started_at->value();');
    expect($moduleSelfServeRoute)->toContain('$wash_started_at = $machine_start_triggered_at;');
    expect($moduleSelfServeRoute)->toContain('$wash_started_at = $format_wash_started_at($selfserve->lane($lane_id)->getWashStartTime());');
    expect($moduleSelfServeRoute)->toContain('\'wash_started_at\' => $wash_started_at');
});
