package com.android.commands.monkey.ape.jev;

import com.android.commands.monkey.ape.model.State;
import com.android.commands.monkey.ape.tree.GUITree;

/** Read-only navigation projection layered after semantic PROMOTE decisions. */
public final class JevSemanticNavigationMask {
    private final JevRegistry registry;
    public JevSemanticNavigationMask(JevRegistry history){registry=history;}
    public boolean allow(State state,GUITree tree,JevSemanticReview.Candidate candidate) {
        if(state==null||tree==null||candidate==null)return false;
        if(registry.hasExactExecution(state,candidate.action,tree,candidate.node))return false;
        // The current page's local PROBE opportunity is governed by its own
        // review decision and native validator.  The global execution index
        // is only a navigation-target gate; it must not suppress this local
        // candidate merely because a related identity was seen elsewhere.
        if(candidate.action.getResolvedGUITree()==tree)return true;
        ConcreteActionIdentity identity=ConcreteActionIdentity.of(candidate.action.getType().name(),candidate.node);
        return !registry.hasRelatedConcreteExecution(identity.actionType(),state.getActivity(),identity.canonicalFullName());
    }
}
