<?php

namespace App\Http\Resources\Api\v1\Taxonomy;

use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;

class TaxonomyResource extends JsonResource
{
    public function toArray(Request $request): array
    {
        return [
            'id' => $this->id,
            'parent_id' => $this->parent_id,
            'name' => $this->name,
            'slug' => $this->slug,
            'handle' => $this->handle,
            'content' => $this->content,
            'image_path' => $this->image_path,
            'status' => $this->status,
            'ordernum' => $this->ordernum,
            'sub_categories' => $this->whenLoaded('childrenRecursive', function () {
                return TaxonomyResource::collection($this->childrenRecursive);
            }),
        ];
    }
}
