<?php

namespace App\Domains\Auth\Services;

use App\Domains\Auth\Models\User;
use App\Domains\Authorization\Enums\RoleCode;

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

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

        return $user;
    }
}
