<?php

namespace App\Modules\DefaultQueryForResourceIndex\Repositories;

use Illuminate\Database\Eloquent\Builder;

class DefaultQueryForResourceIndexRepository
{
    /**
     * Default filament table query builder
     *
     * @param  Builder<\Illuminate\Database\Eloquent\Model>  $query
     */
    public static function make(Builder $query): void
    {
        if (user()->isAdmin()) {
            return;
        }

        if (user()->isSystemUser()) {
            $query->whereIn('branch_id', user()->branches()->pluck('branches.id'));

            return;
        }

        $query->where('user_id', user()->id);
    }
}
