<?php

namespace Modules\Routing\Services;

use Modules\Routing\Data\PriceQuoteData;
use Modules\Routing\Exceptions\RoutePricingNotFoundException;
use Modules\Routing\Models\EvRoute;
use Modules\Shared\Enums\VehicleOption;

class PricingService
{
    public function quote(EvRoute $route, VehicleOption $vehicleOption): PriceQuoteData
    {
        $pricing = $route->pricing()
            ->where('vehicle_option', $vehicleOption)
            ->first();

        if (! $pricing) {
            throw RoutePricingNotFoundException::forRouteAndOption($route, $vehicleOption);
        }

        return new PriceQuoteData(
            evRouteId: $route->id,
            vehicleOption: $vehicleOption,
            price: (string) $pricing->price,
        );
    }
}
