CRITICAL_FIELDS = ['page_id', 'problem_intent', 'query_cluster_ref', 'canonical_url', 'visible_content_contract', 'structured_data_type', 'required_properties', 'markup_validation_state', 'claim_registry_refs', 'internal_link_role', 'primary_cta', 'conversion_destination', 'indexability_state', 'approval_state', 'measurement_event', 'evidence_ref']

def evaluate(c):
    missing=[k for k in CRITICAL_FIELDS if c.get(k) in (None,"",[],{})]
    evidence_complete=not missing
    markup_visibility_valid=bool(c.get("markup_visibility_valid",True))
    canonical_identity_valid=not bool(c.get("near_duplicate_without_distinct_intent",False)) and bool(c.get("canonical_signal_consistent",True))
    intent_claim_alignment_valid=bool(c.get("intent_claim_alignment_valid",True))
    cta_alignment_valid=bool(c.get("cta_alignment_valid",True))
    rich_result_claim_valid=not bool(c.get("rich_result_guaranteed",False))
    if not evidence_complete:
        state="HOLD_MISSING_EVIDENCE"
    elif not canonical_identity_valid and c.get("near_duplicate_without_distinct_intent",False):
        state="CONSOLIDATE_DUPLICATE_INTENT"
    elif not bool(c.get("canonical_signal_consistent",True)):
        state="HOLD_CANONICAL_CONFLICT"
    elif not markup_visibility_valid:
        state="REVISE_MARKUP_VISIBILITY"
    elif not intent_claim_alignment_valid:
        state="HOLD_INTENT_CLAIM_DRIFT"
    elif not cta_alignment_valid:
        state="REVISE_CTA_INTENT"
    elif not rich_result_claim_valid:
        state="HOLD_RICH_RESULT_OVERCLAIM"
    else:
        state="READY"
    return {"state":state,"evidence_complete":evidence_complete,"markup_visibility_valid":markup_visibility_valid,"canonical_identity_valid":canonical_identity_valid,"intent_claim_alignment_valid":intent_claim_alignment_valid,"cta_alignment_valid":cta_alignment_valid}
