<?php

namespace Modules\Category\Models\Resources;

use Illuminate\Http\Resources\Json\JsonResource;
use Modules\Banner\Models\Resources\BannerResource;
use Modules\Region\Models\Resources\RegionResource;
use Modules\Type\Models\Resources\TypeResource;

class CategoryResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'show_footer' => $this->show_footer,
            'show_home' => $this->show_home,
            'max_count_order' => $this->max_count_order,
            'image' => asset($this->image),
            'title'=>$this->currentDescription->title,
            'banner'=>new BannerResource($this->whenLoaded('banner')),
            'main'=>new CategoryResource($this->whenLoaded('main')),
            'type'=>new TypeResource($this->whenLoaded('type')),
            'sub'=>CategoryResource::collection($this->whenLoaded('sub'))
        ];
    }
}
