1"""Display details for a specified email account."""
2# :license: MIT, see LICENSE for more details.
3
4import click
5from SoftLayer.CLI.email.list import build_statistics_table
6from SoftLayer.CLI import environment
7from SoftLayer.CLI import formatting
8from SoftLayer.managers.email import EmailManager
9from SoftLayer import utils
10
11
12@click.command()
13@click.argument('identifier')
14@environment.pass_env
15def cli(env, identifier):
16    """Display details for a specified email."""
17
18    email_manager = EmailManager(env.client)
19    result = email_manager.get_instance(identifier)
20
21    table = formatting.KeyValueTable(['name', 'value'])
22    table.align['name'] = 'r'
23    table.align['value'] = 'l'
24
25    table.add_row(['id', result.get('id')])
26    table.add_row(['username', result.get('username')])
27    table.add_row(['email_address', result.get('emailAddress')])
28    table.add_row(['create_date', result.get('createDate')])
29    table.add_row(['category_code', utils.lookup(result, 'billingItem', 'categoryCode')])
30    table.add_row(['description', utils.lookup(result, 'billingItem', 'description')])
31    table.add_row(['type_description', utils.lookup(result, 'type', 'description')])
32    table.add_row(['type', utils.lookup(result, 'type', 'keyName')])
33    table.add_row(['vendor', utils.lookup(result, 'vendor', 'keyName')])
34
35    statistics = email_manager.get_statistics(identifier)
36
37    for statistic in statistics:
38        table.add_row(['statistics', build_statistics_table(statistic)])
39
40    env.fout(table)
41