<?php

namespace App\Modules\Pilkades\Models\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Support\Facades\Auth;

class DesaScope implements Scope
{
    public function apply(Builder $builder, Model $model): void
    {
        $user = Auth::user();

        if ($user && $user->isAdminDesa() && $user->desa_id) {
            $builder->where($model->getTable().'.desa_id', $user->desa_id);
        }
    }
}
