<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class SearchProperties extends JsonResource
{
    public function toArray($request)
    {
        if ($this->images()->count() > 0) {
            $image = new PropertyImages($this->images->first(), '520x340');
        } else {
            $image = (object)[];
            $image->image = (object)[
                "url" => null,
                "alt" => null,
            ];
        }
        $out = [
            'id'           => (int)$this->id,
            'slug'         => $this->lang_slug,
            'title'        => $this->epigraph_title,
            'image'        =>  $image,
            'isAccessable' => $this->accesses->count() > 0,
            'address'      => $this->searchable_address,
            'type'         => "Property",
            'local'        => $this->local ? $this->local->title : ""
        ];

        return $out;
    }
}
