protected function getUserId($user) : ?int
    {
        if ($user === null) {
            return null;
        }

        if (is_int($user)) {
            return $user;
        }

        if ($user instanceof Authenticatable) {
            return $user->getAuthIdentifier();
        }

        return null;
    }