from dataclasses import dataclass
from typing import Tuple

from hivemind.utils import Endpoint


@dataclass(frozen=True)
class GroupInfo:
    """ A group of peers assembled through decentralized matchmaking """
    group_id: bytes  # random unique bytestring that describes the current group, generated by group leader
    endpoints: Tuple[Endpoint, ...]  # an ordered sequence of endpoints of each groupmate
    gathered: Tuple[bytes, ...]  # binary metadata gathered from all peers by leader, same order as endpoints

    @property
    def group_size(self):
        return len(self.endpoints)

    def __contains__(self, endpoint: Endpoint):
        return endpoint in self.endpoints
