from typing import Container


def get_mag_frequency(plate, speed):
    """Determine frequency for KF operation

    Based on plate type and the desired KF speed, determine the frequency for
    the KF operation. Needed for `mix` and `release` operations.

    Parameters
    ----------
    plate: Container
        Container that is being used
    speed: string
        String defining the speed - can be `slow`, `medium`, `fast`

    .. code-block:: python

            from autoprotocol import Protocol
            from autoprotocol_utilities.magnetic_helpers import get_mag_frequency

            p = Protocol()
            example_plate = p.ref(name="Example", id=None, cont_type="96-pcr", storage="ambient")
            result = get_mag_frequency(plate=example_plate, speed="slow")


    Returns
    -------
    string
        Frequency in the form of "2.5:Hz"

    Raises
    ------
    ValueError
        If `plate` is not of type `Container`
    ValueError
        If `speed` is not 'slow', 'medium', 'fast'
    ValueError
        If plate type is not a key in `frequencies`
    """
    name = plate.container_type.shortname

    frequencies = {"96-deep-kf": {"slow": "0.15:hertz", "medium": "1.5:hertz",
                                  "fast": "2.5:hertz"},
                   "96-deep": {"slow": "0.15:hertz", "medium": "1.5:hertz",
                               "fast": "2.5:hertz"},
                   "96-v-kf": {"slow": "0.5:hertz", "medium": "4.5:hertz",
                               "fast": "9.5:hertz"},
                   "96-flat": {"slow": "0.5:hertz", "medium": "5.5:hertz",
                               "fast": "11.5:hertz"},
                   "96-pcr": {"slow": "0.4:hertz", "medium": "4:hertz",
                              "fast": "8.5:hertz"}}
    assert isinstance(plate, Container)
    assert speed in ['slow', 'medium', 'fast']
    assert name in frequencies.keys()

    return frequencies[name][speed]