import copy
from typing import Any
from typing import Dict


def check(
    hub,
    name: str,
    ctx: Dict[str, Any],
    condition: Any,
    reqret: Dict[str, Any],
    chunk: Dict[str, Any],
    managed_state: Dict[str, Any],
    execution_seq: Dict,
) -> Dict[str, Any]:
    """
    Check to see if the reqret state will make changes in the future
    """
    # condition = "changes"
    # First, prepare the ctx for the reqret chunk
    # Execute the reqret chunk in test mode
    # if the condition returns True then no errors are presented
    ret = {"errors": []}
    ctx = copy.deepcopy(ctx)
    ctx["test"] = True
    r_chunk = copy.deepcopy(reqret["chunk"])
    func = hub.idem.rules.init.get_func(name, r_chunk)
    r_chunk["ctx"] = ctx
    call_kwargs = hub.idem.tools.format_call(
        fun=func,
        data=r_chunk,
        expected_extra_kws=hub.idem.rules.init.STATE_INTERNAL_KEYWORDS,
    )
    sret = func(**call_kwargs)
    cond = sret.get(condition, False)
    if not cond:
        ret["errors"].append(
            f"No {condition} found in execution of {reqret['state']}.{reqret['name']}"
        )
    return ret
