<?php

namespace App\Http\Resources;

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

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

    public function toArray($request)
    {
        return [
            'id'                => $this->id,
            'title'             => $this->title,
            'description'       => strip_tags($this->description),
            'publishDate'       => !empty($this->publish_date) ? Carbon::parse($this->publish_date)->format('d-m-Y') : '',
            'expirationDate'    => !empty($this->expiration_date) ? Carbon::parse($this->expiration_date)->format('d-m-Y') : '',
            'slug'              => '/' . $this->lang_slug,
            'topics'            => TopicResource::collection($this->topics),
            'documentType'      => new DocumentTypeResource($this->documentType),
            'country'           => new CountryResource($this->country),
            'tags'              => DocumentTagResource::collection($this->tags),
            'document'          => new DocumentFileResource($this->documentFile),
            'image'             => getImage($this->image, ['w400', 'w800']),
        ];
    }
}
