<?php

namespace Modules\Activity\Transformers;

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

class ActivityListResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'activity_type_id' => $this->activity_type_id,
            'activity_type' => new ActivityTypeResource($this->whenLoaded('activityType')),
            'title' => $this->title,
            'reference_number' => $this->reference_number,
            'description' => $this->description,
            'start_datetime' => $this->start_datetime?->toISOString(),
            'end_datetime' => $this->end_datetime?->toISOString(),
            'organizer' => $this->organizer,
            'location' => $this->location,
            'is_active' => $this->is_active,
            'gallery_image_count' => $this->gallery_images_count ?? 0,
            'documents_count' => $this->attachments_count ?? 0,
            'cover_image' => $this->when(
                $this->relationLoaded('galleryImages') && $this->galleryImages->isNotEmpty(),
                fn () => new ActivityGalleryImageResource($this->galleryImages->first())
            ),
            'created_at' => $this->created_at?->toISOString(),
            'updated_at' => $this->updated_at?->toISOString(),
        ];
    }
}
