<?php

namespace App\Http\Resources\V1;

use App\Models\Collection;
use App\Models\Exhibition;
use App\Models\NewsItem;
use App\Models\Artist;
use App\Models\Location;
use Illuminate\Http\Resources\Json\JsonResource;

class SearchResultResource extends JsonResource
{


    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id'         => $this->resource->object_id,
            'title'      => $this->title,
            'url'        => $this->url,
            'type'       => $this->getType(),
            'image'      => $this->image
        ];
    }


    /**
     * Returns a readable string based on the class
     */
    private function getType(): string
    {

        switch ($this->object_type) {
            case Collection::class:
                return 'collection';
            case NewsItem::class:
                return 'news';
            case Artist::class:
                return 'artist';
            case Exhibition::class:
                return 'exhibition';
            case Location::class:
                return 'location';
            default:
                return 'n/a';
        }
    }
}
