<?php

namespace TPS\API\Http\Controllers;

use TPS\API\Http\Resources\Catalog\Attribute;
use TPS\API\Http\Resources\Catalog\Category;
use Webkul\API\Http\Controllers\Shop\CategoryController;

class Categories extends CategoryController
{
    public function index()
    {
        return Category::collection(
            $this->categoryRepository->getVisibleCategoryTree(request()->input('parent_id'))
        );
    }

    public function filters($id){
        $category = $this->categoryRepository->with(['filterableAttributes'])->find($id);

        if($category)
            return response([
                'attributes' =>Attribute::collection($category->filterableAttributes),
            ]);
        else{
            return response(['error'=>'not found'],404);
        }
    }
}