<?php

namespace Modules\Category\Resources\Api;

use Illuminate\Http\Resources\Json\JsonResource;

class CategoryResource extends JsonResource
{

    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $return = [
            'id' => (int) $this->id,
            'image' => $this->image ? asset($this->image) : null,
        ];
        if (!$this['ar']) {
            $return['name'] = $this->currentDescription->title ?? "";
            $return['description'] = $this->currentDescription->description ?? "";
        }
        if ($this['ar']) {
            $return['name'] = $this['ar']->title ?? "";
            $return['name_en'] = $this['en']->title ?? "";
            $return['description'] = $this['ar']->description ?? "";
            $return['description_en'] = $this['enr']->description ?? "";
        }
        return $return;
    }

}
