package click.kamil.springstatemachineexporter.analysis.flow.eventid;

import click.kamil.springstatemachineexporter.analysis.flow.alloc.ReceiverFacts;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;

/**
 * Proven virtual accessor on a receiver with allocation (or concrete-type) facts.
 */
public final class AccessProof {

    private final ReceiverFacts receiverFacts;
    private final String accessorName;
    private final MethodInvocation accessorCall;
    private final MethodDeclaration enclosingMethod;

    public AccessProof(
            ReceiverFacts receiverFacts,
            String accessorName,
            MethodInvocation accessorCall,
            MethodDeclaration enclosingMethod) {
        this.receiverFacts = receiverFacts == null ? ReceiverFacts.empty() : receiverFacts;
        this.accessorName = accessorName;
        this.accessorCall = accessorCall;
        this.enclosingMethod = enclosingMethod;
    }

    public ReceiverFacts receiverFacts() {
        return receiverFacts;
    }

    public String accessorName() {
        return accessorName;
    }

    public MethodInvocation accessorCall() {
        return accessorCall;
    }

    public MethodDeclaration enclosingMethod() {
        return enclosingMethod;
    }

    public boolean isValid() {
        return accessorName != null
                && !accessorName.isBlank()
                && !receiverFacts.isEmpty();
    }
}
