<?php

namespace Modules\Routing\Http\Resources;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class RouteTimeSlotResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'label' => $this->label,
            'time' => $this->time?->format('H:i'),
            'is_active' => $this->whenPivotLoaded('ev_route_time_slots', fn () => (bool) $this->pivot->is_active),
        ];
    }
}
