from typing import Union
from typing import Dict
from typing import Any
from typing import List
from typing import Tuple
import math


def computeWaveDataMaxTime(data: Union[Dict[str, Any], List[Dict[str, Any]]], dt: float) -> Tuple[float, int]:
    """
    Compute the pulse duration time of all the wave data input.

    :param data: waveData or waveData list
    :param dt: sampling time step
    :return: a tuple of duration time in Nano-second and dt (AWG sampling interval)
    """
    if isinstance(data, dict):
        maxNs = data["insert_ns"] + data["duration_ns"]
        maxDt = math.floor(maxNs / dt)
    else:
        # Find the max time
        maxNs = 0
        for waveform in data:
            finalNs = waveform["insert_ns"] + waveform["duration_ns"]
            if maxNs < finalNs:
                maxNs = finalNs
        maxDt = math.floor(maxNs / dt)

    return maxNs, maxDt