# Path: roadmaptools/init.py

# 
# Path: roadmaptools/printer.py
# def print_info(info, file=sys.stdout, end="\n"):
#     print("[{0}]: {1}".format(datetime.now().strftime('%H:%M:%S'), info), file=file, end=end)


from roadmaptools.init import config
from typing import Tuple, List
from roadmaptools.printer import print_info
import roadmaptools.inout
import overpass
import osm2geojson
WAY_FILTER = """
	[highway~"(motorway|motorway_link|trunk|trunk_link|primary|primary_link|secondary|secondary_link|tertiary|tertiary_link|unclassified|unclassified_link|residential|residential_link|living_street)"]
	[access!="no"]
"""


def _convert_json_to_geojson(json):

	# way to node list dict
	node_dict = {}
	for el in json['elements']:
		if el['type'] == 'way':
			node_dict[el['id']] = el['nodes']

	geojson = osm2geojson.json2geojson(json)

	# converting geojson to desired format
	for feature in geojson['features']:
		if feature['geometry']['type'] == 'LineString':
			feature['id'] = feature['properties']['id']
			del feature['properties']['id']
			for key, val in feature['properties']['tags'].items():
				feature['properties'][key] = val
			del feature['properties']['tags']
			feature['properties']['nodes'] = node_dict[feature['id']]

	return geojson


def call_overpass(query: str, filepath: str):

# Path: roadmaptools/init.py

# 
# Path: roadmaptools/printer.py
# def print_info(info, file=sys.stdout, end="\n"):
#     print("[{0}]: {1}".format(datetime.now().strftime('%H:%M:%S'), info), file=file, end=end)


# Path: roadmaptools/download_map.py
from roadmaptools.init import config
from typing import Tuple, List
from roadmaptools.printer import print_info
import roadmaptools.inout
import overpass
import osm2geojson

WAY_FILTER = """
	[highway~"(motorway|motorway_link|trunk|trunk_link|primary|primary_link|secondary|secondary_link|tertiary|tertiary_link|unclassified|unclassified_link|residential|residential_link|living_street)"]
	[access!="no"]
"""


def _convert_json_to_geojson(json):

	# way to node list dict
	node_dict = {}
	for el in json['elements']:
		if el['type'] == 'way':
			node_dict[el['id']] = el['nodes']

	geojson = osm2geojson.json2geojson(json)

	# converting geojson to desired format
	for feature in geojson['features']:
		if feature['geometry']['type'] == 'LineString':
			feature['id'] = feature['properties']['id']
			del feature['properties']['id']
			for key, val in feature['properties']['tags'].items():
				feature['properties'][key] = val
			del feature['properties']['tags']
			feature['properties']['nodes'] = node_dict[feature['id']]

	return geojson


def call_overpass(query: str, filepath: str):

	print_info("Downloading map from Overpass API")