<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use App\Models\GenericBackoffice\WebsiteObject;

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

    public function __construct($resource)
    {
        $this->resource = $resource;
    }

    public function toArray($request)
    {
        $activeLang = getActiveLanguage();
        $url = $activeLang === 'en' ? $this->lang_uri : '/' . $activeLang . $this->lang_uri;
        if ($this->bluetoothVersion) {
            $title = $this->bluetoothVersion->title;
        } else {
            $title = null;
            $url = null;
        }
        $out = [
            'id'    => (int)$this->id,
            'title' => $title,
            'url'   => $url,
            'isExternal' => false,
        ];

        return $out;
    }
}
