<?php

namespace Modules\Routing\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Modules\Catalog\Http\Resources\DestinationResource;
use Modules\Catalog\Http\Resources\EvCompanyResource;

class EvRouteResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'is_active' => $this->is_active,
            'company' => new EvCompanyResource($this->whenLoaded('company')),
            'from_destination' => new DestinationResource($this->whenLoaded('fromDestination')),
            'to_destination' => new DestinationResource($this->whenLoaded('toDestination')),
            'time_slots' => RouteTimeSlotResource::collection($this->whenLoaded('timeSlots')),
            'pricing' => RoutePricingResource::collection($this->whenLoaded('pricing')),
        ];
    }
}
