from abc import ABC, abstractmethod
from typing import List, Optional

from server.game.message import MessageToPlayer
from server.model.players import Player


class ClientManager(ABC):
    """
    A listener of game state that notifies clients.
    """

    def __init__(self):
        self.players: List[Player] = []

    def notify(self, message: MessageToPlayer, only_for: Optional[Player] = None) -> None:
        to = [only_for] if only_for else self.players
        for p in to:
            self.send(p, message)

    @abstractmethod
    async def send(self,
                   to: Player,
                   message: MessageToPlayer,
                   extras=None):
        raise NotImplementedError("Send a message to clients ")
