'Remove a relationship between a user and another user or subreddit
The user can either be passed in by name (nuser)
or by [fullname](#fullnames) (iuser).  If type is friend or enemy,
\'container\' MUST be the current user\'s fullname;
for other types, the subreddit must be set
via URL (e.g., /r/funny/api/unfriend)
OAuth2 use requires appropriate scope based
on the \'type\' of the relationship:
* moderator: `modothers`
* moderator_invite: `modothers`
* contributor: `modcontributors`
* banned: `modcontributors`
* muted: `modcontributors`
* wikibanned: `modcontributors` and `modwiki`
* wikicontributor: `modcontributors` and `modwiki`
* friend: Use [/api/v1/me/friends/{username}](#DELETE_api_v1_me_friends_{username})
* enemy: `privatemessages`
Complement to [POST_friend](#POST_api_friend)'

@allow_oauth2_access
@noresponse(VUser(), VModhash(), nuser=VExistingUname('name'), iuser=VByName('id'), container=nop('container'), type=VOneOf('type', (('friend', 'enemy') + _sr_friend_types)))
@api_doc(api_section.users, uses_site=True)
def POST_unfriend(self, nuser, iuser, container, type):

    self.check_api_friend_oauth_scope(type)
    victim = (iuser or nuser)
    if (not victim):
        abort(400, 'No    user    specified')
    if (type in self._sr_friend_types):
        mod_action_by_type = dict(banned='unbanuser', moderator='removemoderator', moderator_invite='uninvitemoderator', wikicontributor='removewikicontributor', wikibanned='wikiunbanned', contributor='removecontributor', muted='unmuteuser')
        action = mod_action_by_type.get(type, type)
        if isinstance(c.site, FakeSubreddit):
            abort(403, 'forbidden')
        container = c.site
        if (not ((c.user == victim) and (type == 'moderator'))):
            if c.user._spam:
                return
            VNotInTimeout().run(action_name=action, target=victim)
    else:
        container = VByName('container').run(container)
        if (not container):
            return
    required_perms = []
    if (c.user != victim):
        if type.startswith('wiki'):
            required_perms.append('wiki')
        else:
            required_perms.append('access')
            if (type == 'muted'):
                required_perms.append('mail')
    if ((not c.user_is_admin) and (type in self._sr_friend_types) and (not container.is_moderator_with_perms(c.user, *required_perms))):
        abort(403, 'forbidden')
    if ((type == 'moderator') and (not c.user_is_admin) and (not container.can_demod(c.user, victim))):
        abort(403, 'forbidden')
    if ((type in ('friend', 'enemy')) and (container != c.user)):
        abort(403, 'forbidden')
    fn = getattr(container, ('remove_' + type))
    new = fn(victim)
    if (new and (type == 'moderator') and (victim != c.user)):
        send_mod_removal_message(container, c.user, victim)
    if (new and (type in self._sr_friend_types)):
        ModAction.create(container, c.user, action, target=victim)
    if ((type == 'friend') and c.user.gold):
        c.user.friend_rels_cache(_update=True)
    if (type in ('banned', 'wikibanned')):
        container.unschedule_unban(victim, type)
    if (type == 'muted'):
        MutedAccountsBySubreddit.unmute(container, victim)
