<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Carbon;

class PressReleaseListResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */

    public function toArray($request)
    {
        return [
            'id'                  => $this->id,
            'slug'                => '/' . $this->lang_slug,
            'title'               => $this->title,
            'country'             => new CountryResource($this->country),
            'date'                => !empty($this->date) ? Carbon::parse($this->date)->format('d-m-Y') : '',
            'topic'               => new TopicResource($this->topic),
            'image'               => getImage($this->image, ['w1920', 'w800', 'w400']),
            'imageMobile'         => getImage($this->imageMobile, ['w840', 'w400']),
            'tags'                => DocumentTagResource::collection($this->tags),
        ];
    }
}
