<?php

namespace App\Http\Resources\Messaging;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\Storage;

class MessageResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @return array<string, mixed>
     */
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'senderId' => $this->user_id,
            'senderName' => $this->sender_name,
            'senderAvatarUrl' => $this->sender_avatar_url,
            'body' => $this->body,
            'imageUrl' => $this->image_url ? asset(Storage::url($this->image_url)) : null,
            'readAt' => $this->read_at,
            'createdAt' => $this->created_at,
        ];
    }
}
