<?php

namespace Modules\Activity\Transformers;

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

class ActivityGalleryImageResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        $activityId = $this->documentable_id;

        return [
            'id' => $this->id,
            'activity_id' => $activityId,
            'name' => $this->name,
            'description' => $this->description,
            'mime_type' => $this->mime_type,
            'file_size' => $this->file_size,
            'uploaded_by' => $this->uploaded_by,
            'url' => $activityId
                ? url(route('api.activity.serve-gallery-image', [
                    'activity' => $activityId,
                    'imageId' => $this->id,
                ]))
                : null,
            'created_at' => $this->created_at?->toISOString(),
        ];
    }
}
