Similar to my suggestion to your earlier question, I think you should give your roles the necessary permissions to edit/create/add children for all the templates they will be working with. If you don't do this you're going to be fighting against what PW thinks that users with those roles are allowed to do and it will be more difficult to achieve what you want. Once those roles have the generic permissions to do what they need to do then focus on selectively taking away those permissions in your custom hooks according to your test on $user, $page, $parent, etc.
Also, I've never understood the advantage to not explicitly setting access to every template. "Inheriting" access just seems like a recipe for confusion and accidental oversight. It only takes a short while to set the template access you want roles to have, and even less time if you use the Template Access module.
Below is some code with demo logic for determining the allowed templates. You would replace that with your own logic which I expect would use some combination of $parent and $user.
$wire->addHookAfter('ProcessPageAdd::getAllowedTemplates', function(HookEvent $event) {
$allowed = $event->return;
$parent_id = (int) $event->wire()->input->get('parent_id');
if(!$parent_id) return;
$parent = $event->wire()->pages->get($parent_id);
// Your custom logic here to remove any disallowed templates
if($parent->template == 'basic_page' && $event->wire()->user->name === 'test-editor') {
$allowed_template_ids = [29, 78];
foreach($allowed as $template_id => $template) {
if(!in_array($template_id, $allowed_template_ids)) {
unset($allowed[$template_id]);
}
}
$event->return = $allowed;
}
});