<?php

namespace App\Http\Resources;

use App\Http\Resources\Image as ImageResource;
use Illuminate\Http\Resources\Json\JsonResource;

class User extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'data' => [
                'type' => 'users',
                'user_id' => $this->id,
                'attributes' => [
                    'name' => $this->name,
                    'email' => $this->email,
                    'profile_image' => new ImageResource($this->profileImage),
                    'cover_image' => new ImageResource($this->coverImage),
                    'thumbnail_cover_image' => new ImageResource($this->thumbnailImage),
                    'last_login' => optional($this->login_at)->diffForHumans(),
                    'is_admin' => $this->isAdmin(),
                ],
            ],
            'links' => [
                'self' => url('/users/'.$this->id),
            ]
        ];
    }
}
