<?php

namespace App\Http\Controllers\Api\V1\Filters\Helpers;

use Laravel\Nova\Makeable;

class BrandsFilter
{
    use Makeable;

    public function __construct(
        protected Builder $queryBuilder,
        protected Request $request,
    ) {}

    /**
     * Basic queries
     */
    public function applyBaseQueries(): self
    {
        $this->queryBuilder->where('is_visible', true)->ordered();

        return $this;
    }

    /**
     * Get brands
     */
    public function get()
    {
        return $this->queryBuilder->whereIntegerInRaw(
            column: 'id',
            values: $resource->products()->distinct('brand_id')->pluck('brand_id')
        )->get(['id', 'name']);

        return $this->queryBuilder->get(['id', 'name']);
    }
}
