import json


def get_stim_params_from_config_for_physiology_factsheet(prot_path, protocol_key):
    """Get step amplitude, delay and duration for phisiology factsheet.

    Args:
        prot_path (str or Path): path to the json file containing the protocols
        protocol_key (str): name of the protocol used for physiology features extraction

    Returns:
        a tuple containing

        - current_amplitude (int or float): the amplitude current of the step protocol (mA)
        - stim_start (int or float): the start of the stimulus (ms)
        - stim_duration (int or float): the duration of the stimulus (ms)

    Raises:
        Exception: If a step protocol with multiple steps has been provided
    """
    with open(prot_path, "r", encoding="utf-8") as protocol_file:
        protocol_definitions = json.load(protocol_file)

    prot = protocol_definitions[protocol_key]
    step_stim = prot["stimuli"]["step"]

    if isinstance(step_stim, list):
        exception_message = (
            "ME-type factsheet expects only one step stimulus "
            + "for protocol {key} at {filepath}"
        )
        raise Exception(exception_message.format(key=protocol_key, filepath=prot_path))

    # get parameters from protocol
    current_amplitude = step_stim["amp"]
    stim_start = step_stim["delay"]
    stim_duration = step_stim["duration"]

    return current_amplitude, stim_start, stim_duration