5b68f4fa38
- Booking model with booking_vehicle_options line items (supports mixing vehicle options like front_seat + back_seat in one booking), price snapshot, status machine, and driver/car assignment fields - BookingService: front-seat max, disabled-option toggles, duplicate-option and whole-vehicle-exclusivity guards - CreateBookingAction, CancelBookingAction, AssignDriverAction - BookingRefGenerator: sequential EVB-AAAAA1-style refs via row lock - POST/GET/cancel booking API endpoints (Sanctum, ownership + admin policy) - BookingPlugin + Filament BookingResource: list, detail view, Cancel and Assign Driver actions (shared between table and detail page) - domain.md updated for multi-vehicle-option bookings (§2) and driver/ vehicle assignment (§5a)
47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Modules\Booking\Exceptions;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Modules\Shared\Enums\VehicleOption;
|
|
use RuntimeException;
|
|
|
|
class InvalidVehicleSelectionException extends RuntimeException
|
|
{
|
|
public static function frontSeatLimitExceeded(int $requested, int $max): self
|
|
{
|
|
return new self("Front seat request [{$requested}] exceeds the max of [{$max}] per booking.");
|
|
}
|
|
|
|
public static function optionDisabled(VehicleOption $vehicleOption): self
|
|
{
|
|
return new self("Vehicle option [{$vehicleOption->value}] is not currently available for booking.");
|
|
}
|
|
|
|
public static function duplicateOption(VehicleOption $vehicleOption): self
|
|
{
|
|
return new self("Vehicle option [{$vehicleOption->value}] was selected more than once — combine it into a single selection.");
|
|
}
|
|
|
|
public static function wholeVehicleCannotBeCombined(): self
|
|
{
|
|
return new self('Whole Vehicle cannot be combined with other vehicle options in the same booking.');
|
|
}
|
|
|
|
/**
|
|
* A rejected vehicle selection is a client input problem, not a server
|
|
* error — surface it as 422 rather than the default 500. A broader JSON
|
|
* error envelope for all of api/* is Phase 6 (T6.3); this keeps the
|
|
* mapping local until that lands.
|
|
*/
|
|
public function render(Request $request): ?JsonResponse
|
|
{
|
|
if ($request->expectsJson()) {
|
|
return response()->json(['message' => $this->getMessage()], 422);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|