from __future__ import annotations

from channels.generic.websocket import WebsocketConsumer

from transcendence.abstract.AbstractRoomMember import AbstractRoomMember

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from .Player import Player
    from .Game import Game

from .Ball import Ball

class Spectator(AbstractRoomMember):

    def __init__(self, user_id: int, socket: WebsocketConsumer, game: Game):
        super().__init__(user_id, socket)
        self.game: Game = game

    def send_paddle(self, player: Player):
        self.send("update_paddle", player.to_dict())    

    def send_ball(self, ball: Ball):
        self.send("update_ball", ball.to_dict())
    
    def disconnect(self, code: int = 1000):
        self.game.leave(self)