import uuid
import random
import csv

emergency_threshold = 5

# too many dictionaries are storing doctor id and could have been
# combined, but they were not made at the same stage
# and combining them now would lead to a lot of changes in a lot of
# code so it's better we use them seperately

# dictionary for doctors_ids and their assigned pcs
doctors_pc = {}

# dictionary for patient_ids and their assigned doctors
patients_doctor = {}

# dictionary for doctor_ids and their accesses and grants
doctors_grants = {}

# dictionary for doctor_ids and their specializations
doctors_spec = {}

# dictionary for doctors and their emergency counts
doctor_em = {}

mac_addresses = []
d_ids = []
p_ids = []
non_hospital_macs = []

# dictionary for specializations, their related data and sensitivity
spec_related_data = {}


def outrandomMAC():
    return [0x07, 0x12, 0x5e,
            random.randint(0x00, 0x7f),
            random.randint(0x00, 0xff),
            random.randint(0x00, 0xff)]


def MACprettyprint(mac):
    return ':'.join(map(lambda x: "%02x" % x, mac))


with open('generated_doctors_data.csv', 'r', encoding="utf8") as csv_read_file:

    # reader object
    csv_reader = csv.DictReader(csv_read_file)

    for line in csv_reader:
        d_ids.append(line['d_id'])
        mac_addresses.append(line['Assigned_PC'])

        doctors_pc[line['d_id']] = line['Assigned_PC']
        doctors_grants[line['d_id']] = [line['Accesses'], line['Grants']]
        doctors_spec[line['d_id']] = line['Speciality']
        doctor_em[line['d_id']] = emergency_threshold
        # print(doctors_spec)
        # print(doctors_grants)
        # print(doctors_pc)


with open('generated_patient_data.csv', 'r', encoding='utf8') as csv_read_file:

    csv_reader = csv.DictReader(csv_read_file)

    for line in csv_reader:
        p_ids.append(line['p_id'])

        patients_doctor[line['p_id']] = line['d_id']
        # print(patients_doctor)

with open('relevance_data.csv', 'r', encoding='utf8') as csv_read_file:

    csv_reader = csv.DictReader(csv_read_file)

    for line in csv_reader:
        spec_related_data[line['Specialization']] = [line['Related_data'].split(','), line['Sensitivity_score']]


for i in range(len(d_ids)):
    non_hospital_macs.append(MACprettyprint(outrandomMAC()))


# test if d_ids are unique
print(len(d_ids))
d = set(d_ids)
print(len(d))

# test if mac addresses are unique
print(len(mac_addresses))
m = set(mac_addresses)
print(len(m))

# append a list to another list
# this is done in order to check if the d_ids and p_ids are same
# because they have been generated by the same method
d_ids.extend(p_ids)

print(len(d_ids))
d = set(d_ids)
print(len(d))


print(spec_related_data)
# print(doctor_em)
