from app.models.friend import Friend

def friend_serialize(friend: list, is_external: bool) -> Friend:
    if friend['status'] != 'pending':
        status = friend['status']
    else:
        if is_external:
            status = 'pending_approval'
        else:
            status = 'pending'

    return Friend(**{
        "id": str(friend["_id"]),
        "friend_user_id": friend["user_id"] if is_external else friend["friend_user_id"],
        "status": status
    })

def friends_serialize(friends: list, external_friends: list) -> dict:
    serialized_friends: list = []

    for friend in friends:
        serialized_friends.append(friend_serialize(friend,False))

    for external_friend in external_friends:
        serialized_friends.append(friend_serialize(external_friend,True))

    return serialized_friends