import random


def generate_candidate_patches(seed, angio_min_x, angio_max_x, angio_min_y, angio_max_y, angio_min_z, angio_max_z, shift_scale_1, vessel_mni_volume_resampled, resampled_tof_volume):
    """This function generates a random angio-tof candidate patch and the corresponding vessel patch
    Args:
        seed (int): random seed used to select a center coordinate
        angio_min_x (int): min non-zero row
        angio_max_x (int): max non-zero row
        angio_min_y (int): min non-zero column
        angio_max_y (int): max non-zero column
        angio_min_z (int): min non-zero slice of numpy volume
        angio_max_z (int): max non-zero slice of numpy volume
        shift_scale_1 (int): half patch side
        vessel_mni_volume_resampled (np.ndarray): vessel mni volume resampled to new spacing
        resampled_tof_volume (np.ndarray): tof volume resampled to new spacing
    Returns:
        random_x_coord (int): x coordinate of random patch center
        random_y_coord (int): y coordinate of random patch center
        random_z_coord (int): z coordinate of random patch center
        random_neg_patch_vessel (np.ndarray): candidate random vessel patch
        random_neg_patch_angio (np.ndarray): candidate random tof patch
    """
    random.seed(seed)  # set fixed random seed; by doing this, the random numbers calculated in the following lines will always be the same
    # randomly pick the [i,j,k] coordinate of the new negative patch that will be created
    random_x_coord = random.randint(angio_min_x, angio_max_x)  # select random column from non-zero columns of BET volume
    random_y_coord = random.randint(angio_min_y, angio_max_y)  # select random row from non-zero rows of BET volume
    random_z_coord = random.randint(angio_min_z, angio_max_z)  # select random slice from non-zero slices of BET volume

    # crop sub-volume from resampled vesselMNI volume
    random_neg_patch_vessel = vessel_mni_volume_resampled[random_x_coord - shift_scale_1:random_x_coord + shift_scale_1,
                                                          random_y_coord - shift_scale_1:random_y_coord + shift_scale_1,
                                                          random_z_coord - shift_scale_1:random_z_coord + shift_scale_1]

    # crop sub-volumes from main volumes with the candidate random center
    random_neg_patch_angio = resampled_tof_volume[random_x_coord - shift_scale_1:random_x_coord + shift_scale_1,
                                                  random_y_coord - shift_scale_1:random_y_coord + shift_scale_1,
                                                  random_z_coord - shift_scale_1:random_z_coord + shift_scale_1]

    return random_x_coord, random_y_coord, random_z_coord, random_neg_patch_vessel, random_neg_patch_angio