from typing import List


def parse_illumiprocessor_config(csv_rows: List[List[str]], double_index: bool = True) -> dict:
    """Read the csv content and creates the illumiprocessor configuration into
    a dictionary to be read by ConfigParser.
    see: https://illumiprocessor.readthedocs.io/en/latest/usage.html#creating-a-configuration-file

    :param csv_rows         rows of the csv table.
    :param double_index     type of indexing of the illumina library.
    :return:                A dictionary to be read by ConfigParser.
    """
    config = dict()
    config["adapters"] = {"i7": csv_rows[0][3], "i5": csv_rows[0][4]}
    config["tag sequences"] = dict()
    config["tag map"] = dict()
    config["names"] = dict()

    for index, row in enumerate(csv_rows):
        tag_name_i7 = f"sample{index}_barcode_i7"
        tag_name_i5 = f"sample{index}_barcode_i5"

        config["tag sequences"][tag_name_i7] = row[1]
        config["tag map"][row[0]] = tag_name_i7
        config["names"][row[0]] = row[0]
        if double_index:
            config["tag sequences"][tag_name_i5] = row[2]
            config["tag map"][row[0]] = f"{tag_name_i7},{tag_name_i5}"

    return config