# Path: server/rooms/utils.py
# def register_room_event_handler(f):
#     from .models.room import Room
#     """Decorator to register function `f` as an event handler"""
#     Room.event_handlers[f.__name__] = f
#     return f


from .utils import register_room_event_handler
import recordings.serializers

@register_room_event_handler
def update_status(event, message, room):
    # TODO refactor this bit - serializer to make sure these are valid
    if 'disk_usage' in event['data']:
        room.peers[message.peer_id]['disk_usage'] = event['data']['disk_usage']
    if 'resources' in event['data']:
        room.peers[message.peer_id]['resources'] = event['data']['resources']
    if 'recorder_status' in event['data']:
        room.peers[message.peer_id]['recorder_status'] = event['data']['recorder_status']
    if 'onboarding_complete' in event['data']:
        room.memberships.filter(
            participant=message.participant
        ).update(
            onboarding_complete=event['data']['onboarding_complete']
        )


# Path: server/rooms/utils.py
# def register_room_event_handler(f):
#     from .models.room import Room
#     """Decorator to register function `f` as an event handler"""
#     Room.event_handlers[f.__name__] = f
#     return f


# Path: server/rooms/events.py
from .utils import register_room_event_handler
import recordings.serializers


@register_room_event_handler
def update_status(event, message, room):
    # TODO refactor this bit - serializer to make sure these are valid
    if 'disk_usage' in event['data']:
        room.peers[message.peer_id]['disk_usage'] = event['data']['disk_usage']
    if 'resources' in event['data']:
        room.peers[message.peer_id]['resources'] = event['data']['resources']
    if 'recorder_status' in event['data']:
        room.peers[message.peer_id]['recorder_status'] = event['data']['recorder_status']
    if 'onboarding_complete' in event['data']:
        room.memberships.filter(
            participant=message.participant
        ).update(
            onboarding_complete=event['data']['onboarding_complete']
        )


@register_room_event_handler