from typing import Tuple
import random


def random_split(smi_list,
                sizes: Tuple[float, float, float] = (0.8, 0.1, 0.1),
                seed: int = 0,
                shuffle: bool = True):
    """
    Split a dataset randomly.
    - parameters
        - data: A list of smiles.
        - sizes: A length-3 tuple with the proportions of data in the train, validation, and test sets.
        - seed: Seed for reproducitility.
    - return: two tuples
        - (1) containing the train, validation, and test splits of the data (SMILES)
        - (2) containing the train, validation, and test splits of the index.
    """
    assert sum(sizes) == 1

    data_index = [i for i in range(len(smi_list))]
    if shuffle:
        random.seed(seed)
        random.shuffle(data_index)

    #split the index into train, valid and test
    train_cutoff = int(len(data_index) * sizes[0])
    val_cutoff = train_cutoff + int(len(data_index) * sizes[1])

    train_index = data_index[:train_cutoff]
    val_index = data_index[train_cutoff: val_cutoff]
    test_index = data_index[val_cutoff:]

    # Map from indices to data
    train = [smi_list[i] for i in train_index]
    val = [smi_list[i] for i in val_index]
    test = [smi_list[i] for i in test_index]

    return (train, val, test), (train_index, val_index, test_index)