import re


def identify_entity(identity):
    """
    Detect the type of OpsGenie entity being processed: an id, username or name.

    identity: string : Expects to be a string containing an OpsGenie entity and
                       it's type separated by a single '-'

    return: A dictionary with the form and type of the entity or None if the identity
            can't be processed.
    """
    res = identity.rsplit("-", 1)
    if len(res) != 2:
        print("Skipping {} because it's not formed as '<identiy>-<type>'".format(identity))
        return None

    re_email = re.compile(r"^[^@]+@[^@]+$")
    re_id = re.compile(r"^[0-9a-z]{8}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{4}-[0-9a-z]{12}$")

    form, type_ = res
    # Detect email form: "trinity@opsgenie.com"
    if type_ == "user" and re.match(re_email, form):
        form_key = "username"
    # Detect id form: "4513b7ea-3b91-438f-b7e4-e3e54af9147c"
    elif re.match(re_id, form):
        form_key = "id"
    # Any other forms are just names.
    else:
        form_key = "name"

    return {form_key: str(form), "type": str(type_)}