<?php

namespace App\Http\Resources;

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

class EventRegistrationResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id'                  => $this->id,
            'registration_number' => $this->registration_number,
            'status'              => $this->status,
            'special_requests'    => $this->special_requests,
            'registered_at'       => $this->registered_at?->toISOString(),
            'event'               => $this->whenLoaded('event', fn () =>
                                        new EventResource($this->event)
                                     ),
            'co_travelers'        => $this->whenLoaded('coTravelers',
                                        EventCoTravelerResource::collection($this->coTravelers)
                                     ),
            'created_at'          => $this->created_at->toISOString(),
        ];
    }
}
