from typing import TextIO
from typing import Tuple
from typing import Dict
import itertools


def _get_metadata(fp: TextIO) -> Tuple[int, Dict[str, str]]:
    """
    Load metadata from a fluke 985 tab-delimited data file.

    Parameters
    ----------
    fp : file-like object
        The data file.

    Returns
    -------
    last_md_line : int
        The index of the blank line between metadata and the table.

    metadata : dict
        A dictionary of metadata, including "Model Number" and others specified
        in the header.
    """
    metadata = {}
    last_md_line = 0
    fp.seek(0)
    for line_number in itertools.count(start=1):
        line = fp.readline().strip()
        if ':' not in line:
            last_md_line = line_number
            break

        key, value = line.split(':', 1)
        metadata[key.strip()] = value.strip()

    return last_md_line, metadata