<?php

it('guards order booking creation with redis-backed idempotency', function (): void {
    $routeFile = app_path('routes/orderBookingRoute.php');
    expect(is_file($routeFile))->toBeTrue();

    $code = (string)file_get_contents($routeFile);
    $normalized = preg_replace('/\s+/', ' ', $code);

    expect($normalized)->toContain('$fingerprint = $this->buildBookingCreationFingerprint($data);');
    expect($normalized)->toContain("'datetime' => \$this->normalizeDatetimeForFingerprint((string)(\$data['datetime'] ?? ''))");
    expect($normalized)->toContain("return \$parsed->format('Y-m-d H:i');");
    expect($normalized)->toContain('reserveBookingCreationSlot($fingerprint)');
    expect($normalized)->toContain('storeBookingIdempotencyResult($fingerprint, (int)$order_bookings_o->id)');
    expect($normalized)->toContain('clearBookingCreationSlot($fingerprint)');
    expect($normalized)->toContain("order_booking:idempotency:lock:");
    expect($normalized)->toContain("order_booking:idempotency:result:");
});
