<?php

namespace App\Modules\Settings\Rbac\Services;

use App\Models\User;
use App\Modules\Admin\Tenancy\Models\Tenant;
use App\Modules\Navigation\Services\NavigationService;
use App\Modules\Settings\Rbac\Repositories\UserRoleRepository;

class TenantUserRoleService
{
    public function __construct(
        private readonly UserRoleRepository $userRoles,
    ) {}

    /**
     * @param  list<int>  $roleIds
     */
    public function syncRoles(Tenant $tenant, User $user, array $roleIds): void
    {
        $this->userRoles->syncRolesForUser($user, (int) $tenant->id, $roleIds);
        TenantPermissionEvaluator::forgetCacheForUser($user);
        NavigationService::forgetForUser($user);
    }
}
