import networkx as nx

#G = nx.path_graph(4)
#nx.write_gpickle(G, "/home/zarah/Downloads/mygraph.gpickle")

def createMyGraph():
    G = nx.classes.graph.Graph()

    # user nodes
    user_nodes = ["L1-Users_Alex"
    ,"L1-Users_Zara"
    ,"L1-Users_Narges"
    ,"L1-Users_Nishant"
    ,"L1-Users_Roland"
    ,"L1-Users_Radu"
    ,"L1-Users_EmptyNode"]
    for user in user_nodes:
        G.add_node(user)

    # car nodes
    G.add_node("L2-cars_car1")
    G.add_node("L2-cars_car2")
    G.add_node("L2-cars_car3")

    # location nodes
    G.add_node("L3-Locations_location1")
    G.add_node("L3-Locations_location2")
    G.add_node("L3-Locations_location3")
    G.add_node("L3-Locations_location4")

    # user-user edges
    G.add_edge("L1-Users_Alex", "L1-Users_Zara", weight=3, key='friend_of')
    G.add_edge("L1-Users_Zara", "L1-Users_Nishant", weight=3, key='friend_of')
    G.add_edge("L1-Users_Nishant", "L1-Users_Radu", weight=3, key='student_of')
    G.add_edge("L1-Users_Narges", "L1-Users_Roland", weight=3, key='friend_of')
    G.add_edge("L1-Users_Roland", "L1-Users_Radu", weight=3, key='student_of')
    G.add_edge("L1-Users_Alex", "L1-Users_Radu", weight=3, key='student_of')
    G.add_edge("L1-Users_Zara", "L1-Users_Radu", weight=3, key='student_of')
    G.add_edge("L1-Users_Narges", "L1-Users_Radu", weight=3, key='student_of')
    ## fully connect users
    # for user1 in user_nodes:
    #     for user2 in user_nodes:
    #         if user1 == user2:
    #             continue
    #         G.add_edge(user1, user2, weight=1, key='friend_of')

    # user-car edges
    G.add_edge("L1-Users_Alex", "L2-cars_car1", key='passenger_of' )
    G.add_edge("L1-Users_Zara", "L2-cars_car2", key='passenger_of')
    G.add_edge("L1-Users_Radu", "L2-cars_car3", key='passenger_of')
    G.add_edge("L1-Users_Roland", "L2-cars_car3", key='passenger_of')
    G.add_edge("L1-Users_Nishant", "L2-cars_car2", key='passenger_of')
    G.add_edge("L1-Users_Narges", "L2-cars_car3", key='passenger_of')

    # user-location edges
    G.add_edge("L1-Users_Alex", "L3-Locations_location1", key='passenger_of')
    G.add_edge("L1-Users_Alex", "L3-Locations_location3", key='passenger_of')
    G.add_edge("L1-Users_Zara", "L3-Locations_location2", key='passenger_of')
    G.add_edge("L1-Users_Zara", "L3-Locations_location4", key='passenger_of')
    G.add_edge("L1-Users_Radu", "L3-Locations_location4", key='passenger_of')
    G.add_edge("L1-Users_Nishant", "L3-Locations_location3", key='passenger_of')
    G.add_edge("L1-Users_Narges", "L3-Locations_location2", key='passenger_of')
    G.add_edge("L1-Users_Roland", "L3-Locations_location1", key='passenger_of')

    # car-location edges
    G.add_edge("L2-cars_car1", "L3-Locations_location1", key='passenger_of')
    G.add_edge("L2-cars_car1", "L3-Locations_location2", key='passenger_of')
    G.add_edge("L2-cars_car2", "L3-Locations_location3", key='passenger_of')
    G.add_edge("L2-cars_car1", "L3-Locations_location4", key='passenger_of')

    return G

def storeGraph(G):
    print(nx.info(G))

    import os
    if not os.path.exists("models"):
        os.makedirs("models")
    nx.write_gpickle(G, "models/dps.gpickle")

G = createMyGraph()
storeGraph(G)