<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class Products extends JsonResource
{
    public function __construct($resource)
    {
        $this->resource = $resource;
    }

    public function toArray($request)
    {
        $videoLink = $this->video_link ?? [];

        $thumbnail = null;
        if ($this->thumbnail) {
            $thumbnail = getImage($this->thumbnail, 'resizeH780');
        }

        $out = [
            'id'          => (int) $this->id,
            'title'       => $this->title,
            'description' => $this->description ?? '',
            'merchant'    => $this->merchant,
            'email'       => $this->email,
            'website'     => $this->website ?? '',
            'telephone'   => $this->telephone ?? '',
            'location'    => $this->location ?? '',
            'address'     => $this->address ?? '',
            'thumbnail'   => $thumbnail,
        ];

        return $out;
    }
}
