# Path: steamapi/getheroes.py
# def requestGetHeroes():
#     URL = "https://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/?key=" + SteamAPIKey + "&language=en_us"
# 
# Path: steamapi/getproplayerlist.py
# def requestGetProPlayerList():
#     URL = "https://api.steampowered.com/IDOTA2Fantasy_570/GetProPlayerList/v1?key=" + SteamAPIKey
# 
# Path: misc/idnamedict.py
# def gameMode(gameModeID):
#     return {
#         -1: 'skipped',
#         0 : 'Unknown',
#         1 : 'All Pick',
#         2 : 'Captains Mode',
#         3 : 'Random Draft',
#         4 : 'Single Draft',
#         5 : 'All Random',
#         6 : '?? INTRO/DEATH ??',
#         7 : 'The Diretide',
#         8 : 'Reverse Captains Mode',
#         9 : 'Greeviling',
#         10 : 'Tutorial',
#         11 : 'Mid Only',
#         12 : 'Least Played',
#         13 : 'New Player Pool',
#         14 : 'Compendium Matchmaking',
#         15 : 'Custom',
#         16 : 'Captains Draft',
#         17 : 'Balanced Draft',
#         18 : 'Ability Draft',
#         19 : '?? Event ??',
#         20 : 'All Random Death Match',
#         21 : '1vs1 Solo Mid',
#         22 : 'Ranked All Pick',
#     }.get(gameModeID, 'Unkown')
# 
# Path: converter/playerconverter.py
# def playerConverter(playerID, playerSummariesJson=None, includeMMR=False):
# def getMMR(playerID):
#     MMR = None
#         MMR = getMMR(playerID)
#         MMR = {}


from steamapi.getheroes import heroDictionary
from steamapi.getproplayerlist import proPlayerDictionary
from misc.idnamedict import gameMode
from converter import playerconverter

#from steamapi.getheroes import heroDictionary, requestGetHeroes

def printTableLine(name, source, divider):
    keyValues = ['kills', 'deaths', 'assists', 'last_hits', 'denies', 'gold_per_min', 'xp_per_min', 'hero_damage', 'tower_damage', 'hero_healing']
    #'level', 'gold', 'gold_spent',

    tableLine = '**%s**' %name
    for key in keyValues:
        tableLine = tableLine + ' | ' +  str(round((source[key]/divider), 2))
    tableLine = tableLine + ' | ' + str(source.get('leaver_status', 0))
    #TODO provide match ids of leaver games (fuck this shit)

    return tableLine + '\n'

def printHeroLine(name, playedHeroes):
    sortedPlayedHeroes = sorted(playedHeroes.keys(), key=lambda x:playedHeroes[x].get('count', 0), reverse=1)
    i = 0

    resultHeroes = str(name) + ' | '

    for heroID in sortedPlayedHeroes:
        if (playedHeroes[heroID]['count'] == 0):
            break


# Path: steamapi/getheroes.py
# def requestGetHeroes():
#     URL = "https://api.steampowered.com/IEconDOTA2_570/GetHeroes/v0001/?key=" + SteamAPIKey + "&language=en_us"
# 
# Path: steamapi/getproplayerlist.py
# def requestGetProPlayerList():
#     URL = "https://api.steampowered.com/IDOTA2Fantasy_570/GetProPlayerList/v1?key=" + SteamAPIKey
# 
# Path: misc/idnamedict.py
# def gameMode(gameModeID):
#     return {
#         -1: 'skipped',
#         0 : 'Unknown',
#         1 : 'All Pick',
#         2 : 'Captains Mode',
#         3 : 'Random Draft',
#         4 : 'Single Draft',
#         5 : 'All Random',
#         6 : '?? INTRO/DEATH ??',
#         7 : 'The Diretide',
#         8 : 'Reverse Captains Mode',
#         9 : 'Greeviling',
#         10 : 'Tutorial',
#         11 : 'Mid Only',
#         12 : 'Least Played',
#         13 : 'New Player Pool',
#         14 : 'Compendium Matchmaking',
#         15 : 'Custom',
#         16 : 'Captains Draft',
#         17 : 'Balanced Draft',
#         18 : 'Ability Draft',
#         19 : '?? Event ??',
#         20 : 'All Random Death Match',
#         21 : '1vs1 Solo Mid',
#         22 : 'Ranked All Pick',
#     }.get(gameModeID, 'Unkown')
# 
# Path: converter/playerconverter.py
# def playerConverter(playerID, playerSummariesJson=None, includeMMR=False):
# def getMMR(playerID):
#     MMR = None
#         MMR = getMMR(playerID)
#         MMR = {}


# Path: displayreddit/draveragelastxgames.py
from steamapi.getheroes import heroDictionary
from steamapi.getproplayerlist import proPlayerDictionary
from misc.idnamedict import gameMode
from converter import playerconverter


#from steamapi.getheroes import heroDictionary, requestGetHeroes

def printTableLine(name, source, divider):
    keyValues = ['kills', 'deaths', 'assists', 'last_hits', 'denies', 'gold_per_min', 'xp_per_min', 'hero_damage', 'tower_damage', 'hero_healing']
    #'level', 'gold', 'gold_spent',

    tableLine = '**%s**' %name
    for key in keyValues:
        tableLine = tableLine + ' | ' +  str(round((source[key]/divider), 2))
    tableLine = tableLine + ' | ' + str(source.get('leaver_status', 0))
    #TODO provide match ids of leaver games (fuck this shit)

    return tableLine + '\n'

def printHeroLine(name, playedHeroes):
    sortedPlayedHeroes = sorted(playedHeroes.keys(), key=lambda x:playedHeroes[x].get('count', 0), reverse=1)
    i = 0

    resultHeroes = str(name) + ' | '

    for heroID in sortedPlayedHeroes:
        if (playedHeroes[heroID]['count'] == 0):
            break


        heroValues = (playedHeroes[heroID]['count'],heroDictionary[heroID],playedHeroes[heroID]['wins'],playedHeroes[heroID]['count'] - playedHeroes[heroID]['wins'], round(100 * playedHeroes[heroID]['wins'] / playedHeroes[heroID]['count'],2))