from datetime import datetime


def days_last_used(client, access_key) -> int:
    """ Calculates when a key was last used

  Parameters
  ----------
  client : object
    The boto client used to make the call
  access_key : str
    Target access key to check

  Returns
  -------
  int
    The number of days since the key was last used

  """

    ## Get current date and time
    current_date_time = datetime.now()
    ## Access Key ID
    access_key_id = access_key.get('AccessKeyId')

    ## Get the last used details
    key_last_used = client.get_access_key_last_used(
        AccessKeyId=access_key_id
    )


    ## Check if key has ever been used, else use creation time
    if 'LastUsedDate' in key_last_used:
        return (current_date_time - key_last_used['LastUsedDate'].replace(tzinfo=None)).days
    else:
        return (current_date_time - access_key['CreateDate'].replace(tzinfo=None)).days