import reverse_geocoder as rg
import pandas as pd


# Permet de modifier un Tuple en Liste
def tupleToList(myTuples, userManage):
    TuplestoList = [list(e) for e in myTuples]  # [[1, 2],[3, 4]]
    for i in TuplestoList:
        if i[4] == userManage:
            i[4] = 'Oui'
        else:
            i[4] = 'Non'
    HalfTuple = [tuple(e) for e in TuplestoList]  # [(1, 2), (3, 4)]
    list_final = (*HalfTuple,)  # ((1, 2), (3, 4))
    return list_final


# Permet de localiser avec coordonées grâce à reverse_geocoder
def localisationUser(lat, lon):
    coordinates = (lat, lon)
    result = rg.search(coordinates, mode=2)
    results_df = pd.DataFrame(result)
    town = str(results_df.iloc[0, 2])
    if str(results_df.iloc[0, 5]) == "FR":
        country = 'France'
    else:
        country = str(results_df.iloc[0, 5])
    return town


# Permet de set les rank en session
def setRank(rank):
    if rank == 'patient':
        result = 0
    if rank == 'proche':
        result = 1
    if rank == 'med':
        result = 2
    if rank == 'admin':
        result = 3
    return result
