import csv


def input_data(name_W, name_AP, name_BP, name_T):
    """
    Generates the different input data in the correct format from .csv files.

    :param name_W: Name of the .csv file which must contain on the first line the name of the criteria and on the
        second line the weightings.
    :param name_AP: Name of the .csv file which must contain on the first line the names of the possibles actions and
        on the following lines the performance of each action against each criterion.
    :param name_BP: Name of the .csv file which must contain on the first line the names of the boundaries actions and
        on the following lines, the performances of each boundary action against each criterion.
    :param name_T: Name of the .csv file which must contain on the first line the names of the thresholds and on the
        following lines, for each criterion, the values of the indifference threshold, preference threshold and veto
        threshold.

    :return C: List containing the names of the criteria as strings.
    :return W: Dictionary containing the weightings of each criterion.
    :return A: List containing the names of the actions as strings.
    :return AP: Actions performances dictionary.
    :return B: List containing the names of the boundary reference actions as strings.
    :return BP: Boundary reference actions performances dictionary.
    :return T: Dictionary of thresholds.
    """
    C = []
    W = {}
    A = []
    AP = {}
    B = []
    BP = {}
    T = {}
    with open(name_W, 'r', newline='') as W_csv:
        reader = csv.reader(W_csv, delimiter=',')
        line_count = 0
        for row in reader:
            if line_count == 0:
                [C.append(item) for item in row]
            else:
                for j in range(len(row)):
                    W[C[j]] = float(row[j])
            line_count += 1

    with open(name_AP, 'r', newline='') as AP_csv:
        reader = csv.reader(AP_csv, delimiter=',')
        line_count = 0
        for row in reader:
            if line_count == 0:
                [A.append(item) for item in row]
            else:
                perf_A = {}
                for j in range(len(row)):
                    perf_A[C[j]] = float(row[j])
                AP[A[line_count-1]] = perf_A
            line_count += 1

    with open(name_BP, 'r', newline='') as BP_csv:
        reader = csv.reader(BP_csv, delimiter=',')
        line_count = 0
        for row in reader:
            if line_count == 0:
                [B.append(item) for item in row]
            else:
                perf_B = {}
                for j in range(len(row)):
                    perf_B[C[j]] = float(row[j])
                BP[B[line_count-1]] = perf_B
            line_count += 1

    with open(name_T, 'r', newline='') as T_csv:
        reader = csv.reader(T_csv, delimiter=',')
        line_count = 0
        for row in reader:
            if line_count == 0:
                line_count += 1
                continue
            else:
                perf_T = []
                [perf_T.append(float(item)) for item in row]
                T[C[line_count-1]] = tuple(perf_T)
            line_count += 1

    return C, W, A, AP, B, BP, T