from typing import OrderedDict


def aks_get_versions_table_format(result):
    """Format get-versions upgrade results as a summary for display with "-o table"."""
    master = result.get('controlPlaneProfile', {})
    result['masterVersion'] = master.get('kubernetesVersion', 'unknown')
    master_upgrades = master.get('upgrades', [])
    result['masterUpgrades'] = ', '.join(master_upgrades) if master_upgrades else 'None available'

    agents = result.get('agentPoolProfiles', [])
    versions, upgrades = [], []
    for agent in agents:
        version = agent.get('kubernetesVersion', 'unknown')
        agent_upgrades = agent.get('upgrades', [])
        upgrade = ', '.join(agent_upgrades) if agent_upgrades else 'None available'
        name = agent.get('name')
        if name:  # multiple agent pools, presumably
            version = "{}: {}".format(name, version)
            upgrade = "{}: {}".format(name, upgrades)
        versions.append(version)
        upgrades.append(upgrade)

    result['nodePoolVersion'] = ', '.join(versions)
    result['nodePoolUpgrades'] = ', '.join(upgrades)

    # put results in an ordered dict so the headers are predictable
    table_row = OrderedDict()
    for k in ['name', 'resourceGroup', 'masterVersion', 'masterUpgrades', 'nodePoolVersion', 'nodePoolUpgrades']:
        table_row[k] = result.get(k)
    return [table_row]