def extract_total_individuals_and_the_ones_within_target_for_both_classes(
    individuals, target
):
    """
    Extract the total number of individuals that pass through the model and the
    total number of individuals that exit the model within the given target.

    Parameters
    ----------
    individuals : list of ciw.individual.Individual objects
    target : float

    Returns
    -------
    int, int, int, int
        - The number of class 2 individuals that pass through the model
        - The number of class 2 individuals that pass through within the target
        - The number of class 1 individuals that pass through the model
        - The number of class 1 individuals that pass through within the target
    """
    class_2_inds, class_2_inds_within_target = 0, 0
    class_1_inds, class_1_inds_within_target = 0, 0
    for individual in individuals:
        ind_class = len(individual.data_records) - 1
        rec = individual.data_records[-1]
        if rec.node == 2 and ind_class == 0:
            class_1_inds += 1
            if rec.waiting_time + rec.service_time < target:
                class_1_inds_within_target += 1
        elif rec.node == 2 and ind_class == 1:
            class_2_inds += 1
            if rec.waiting_time + rec.service_time < target:
                class_2_inds_within_target += 1

    return (
        class_2_inds,
        class_2_inds_within_target,
        class_1_inds,
        class_1_inds_within_target,
    )