<?php

namespace App\Http\Resources;

use App\Models\ServicePackageItem;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;

class ServicePackageItemResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id'                 => $this->id,
            'service_package_id' => $this->service_package_id,
            'schedule_id'        => $this->schedule_id,
            'schedule'           => new ScheduleResource($this->whenLoaded('schedule')),
            'created_at'         => $this->created_at?->toISOString(),
            'updated_at'         => $this->updated_at?->toISOString(),
        ];
    }

    /**
     * @param \Illuminate\Database\Eloquent\Collection<ServicePackageItem> $resource
     * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<ServicePackageItemResource>
     */
    public static function collection($resource): AnonymousResourceCollection
    {
        return parent::collection($resource);
    }
}
