<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def add_resource_types(resource_i, types):
 """ Save a reference to the types used for this resource. @returns a list of type_ids representing the type ids on the resource. """

    if types is None:
        return []

    existing_type_ids = []
    if resource_i.types:
        for t in resource_i.types:
            existing_type_ids.append(t.type_id)

    new_type_ids = []
    for templatetype in types:

        if templatetype.id in existing_type_ids:
            continue

        rt_i = ResourceType()
        rt_i.type_id     = templatetype.id
        rt_i.ref_key     = resource_i.ref_key
        if resource_i.ref_key == 'NODE':
            rt_i.node_id      = resource_i.id
        elif resource_i.ref_key == 'LINK':
            rt_i.link_id      = resource_i.id
        elif resource_i.ref_key == 'GROUP':
            rt_i.group_id     = resource_i.id
        resource_i.types.append(rt_i)
        new_type_ids.append(templatetype.id)

    return new_type_ids