import requests
import json


def getdetailedinfofromid(url, token, personid):
    """

    @param url: url for the webex teams API calls
    @param token: WebEx Teams Token to be used for the queries of the WebEx Teams Cloud
    @param personid: personID of the end user that we would like to return the email to.
    @return: Detailed array of all identification data for the user specifed by the personID field

    This function will take the person ID value and query the WebEx Teams API to return all data associated with the user.
    It includes:

    "avatar":
    "created":
    "displayName":
    "emails":
    "firstName":
    "id":
    "lastName":
    "nickName":
    "orgId":
    "type":

    """

    apistring = url+"/v1/people?id="+personid

    # Set up the Headers based upon the WebEx Teams API
    headers = {'Authorization': 'Bearer {}'.format(token),
            'content-type': 'application/json'}

    # Send the request to the WebEx Teams API using the payload and headers defined above
    try:
        resp = requests.get(apistring, headers=headers)
    except requests.exceptions.RequestException as e:
        print(e)
        return ''

    if resp.status_code == 200:

        message_dict = json.loads(resp.text)
        message_dict['statuscode'] = str(resp.status_code)

        return message_dict['items'][0]
    else:
        return ''