import json


def putTableAll(obj):
    """
    Returns table as string showing standings of league with all data 

    Parameters:
    -----------
    obj: dict
        JSON object of league standings obtained from API/cache

    Returns:
    --------
    str
        Standings as a text code block (to get monospaced text) showing all data 
    """
    try:
        assert(type(obj) == dict)

        fin = open('source/teamcodes.json', 'r')
        mapper = json.load(fin)

        str_re = '```\nLEAGUE: ' + str(obj['competition']['name']) +\
                 ' ' * (45 - 2 - 8 - 10 - len(str(obj['competition']['name']))) +\
                 'MATCHDAY: ' + str(obj['season']['currentMatchday']) + '\n'
        str_re += '╔════╤══════╤════╤════╤════╤════╤═════╤═════╗\n'
        str_re += '║ SN │ TEAM │ M  │ W  │ D  │ L  │ PTS │ GD  ║\n'
        str_re += '╠════╪══════╪════╪════╪════╪════╪═════╪═════╣\n'
        for team in obj['standings'][0]['table']:
            text = '║ %-2d │ %-4s │ %-2d │ %-2d │ %-2d │ %-2d │ %-3d │ %+-3d ║\n'\
                % (team['position'], mapper.get(team['team']['name'], team['team']['name'][:4])[:4], team['playedGames'], team['won'],
                    team['draw'], team['lost'], team['points'], team['goalDifference'])

            str_re += text

        str_re += '╚════╧══════╧════╧════╧════╧════╧═════╧═════╝```'
        fin.close()
        return str_re

    except AssertionError:
        return 'Error!'