<?php

namespace App\Domains\Auth\Services;

use App\Domains\Auth\Models\User;

class ScannerContextService
{
    public function load(User $user): User
    {
        $tenant = $user->tenant()
            ->with([
                'menues' => fn ($query) => $query->whereHas(
                    'roles',
                    fn ($query) => $query->where('codigo', $user->rol_codigo)
                ),
            ])
            ->firstOrFail();

        $user->setRelation('tenant', $tenant);

        return $user;
    }
}
