def downgrade(account):
    """Transforms data from v2 format to a v1 format"""
    d_account = dict(schema_version=1, metadata={'email': account['email']},
                     tags=list(set([account['environment']] + account.get('tags', []))))

    v1_services = {}
    for service in account.get('services', []):
        if service['name'] == 's3':
            if service['metadata'].get('name'):
                d_account['metadata']['s3_name'] = service['metadata']['name']

        elif service['name'] == 'cloudtrail':
            d_account['metadata']['cloudtrail_index'] = service['metadata']['esIndex']
            d_account['metadata']['cloudtrail_kibana_url'] = service['metadata']['kibanaUrl']

        elif service['name'] == 'bastion':
            d_account['bastion'] = service['metadata']['hostname']

        elif service['name'] == 'titus':
            v1_services['titus'] = {
                'stacks': service['metadata']['stacks'],
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'spinnaker':
            v1_services['spinnaker'] = {
                'name': service['metadata'].get('name', account["name"]),
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'awwwdit':
            v1_services['awwwdit'] = {
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'security_monkey':
            v1_services['security_monkey'] = {
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'poseidon':
            v1_services['poseidon'] = {
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'rolliepollie':
            v1_services['rolliepollie'] = {
                'enabled': service['status'][0]['enabled']
            }

        elif service['name'] == 'lazyfalcon':
            owner = None

            if service.get('metadata'):
                if service['metadata'].get('owner'):
                    owner = service['metadata']['owner']

            v1_services['lazyfalcon'] = {
                'enabled': service['status'][0]['enabled'],
                'owner': owner
            }

    if account['provider'] == 'aws':
        d_account['metadata']['account_number'] = account['id']

    elif account['provider'] == 'gcp':
        d_account['metadata']['project_id'] = account['id']

    d_account['id'] = account['provider'] + '-' + account['id']
    d_account['cmc_required'] = account['sensitive']
    d_account['name'] = account['name']
    d_account['alias'] = account['aliases']
    d_account['description'] = account['description']
    d_account['owners'] = account['contacts']
    d_account['type'] = account['provider']
    d_account['ours'] = True if account['owner'] == 'netflix' else False
    d_account['netflix'] = True if account['owner'] == 'netflix' else False
    d_account['services'] = v1_services
    d_account['account_status'] = account['account_status']

    return d_account
Transforms data from v2 format to a v1 format