# Path: modules/queue/Origin.py
# def maxOrigin(a, b):
# 
# Path: modules/game/Game.py
# class Game(NamedTuple('Game', [
#         ('id', GameID),
#         ('white', PlayerID),
#         ('black', PlayerID),
#         ('pgn', List[str]),
#         ('emts', Opt[List[Emt]]),
#         ('analysis', Analysis)
#     ])):
# class GameBSONHandler:
# class GameDB(NamedTuple('GameDB', [
#         ('gameColl', Collection)
#     ])):
#     def fromDict(d: Dict):
#     def fromJson(json: Dict):
#     def toJson(self):
#     def playable(self):
#     def boardTensors(self, colour):
#     def boardTensorsByPlayerId(self, playerId: PlayerID, length: int = 60, safe: bool = True):
#     def tensor(self, playerId: PlayerID, length: int = 60, noisey: bool = False, safe: bool = True) -> Opt[GameTensor]:
#     def emtsByColour(self, colour: Colour, emts: Opt[List[int]] = None) -> List[Emt]:
#     def moveTensor(analysis: Analysis, emt: Emt, boardTensor: List[int], avgEmt: Number, colour: Colour) -> MoveTensor:
#     def nullBoardTensor():
#     def nullMoveTensor() -> MoveTensor:
#     def ply(moveNumber: int, colour: Colour) -> int:
#     def reads(bson: Dict) -> Game:
#     def writes(game: Game) -> Dict:
#     def byId(self, _id: GameID) -> Opt[Game]:
#     def byIds(self, ids: List[GameID]) -> List[Game]:
#     def byPlayerId(self, playerId: PlayerID) -> List[Game]:
#     def byPlayerIdAndAnalysed(self, playerId: PlayerID, analysed: bool = True) -> List[Game]:
#     def write(self, game: Game):
#     def writeMany(self, games: List[Game]):


from default_imports import *
from modules.queue.Origin import Origin
from modules.game.Game import PlayerID
from datetime import datetime
from pymongo.collection import Collection
import pymongo

IrwinQueue = NamedTuple('IrwinQueue', [
        ('id', PlayerID),
        ('origin', Origin)
    ])

class IrwinQueueBSONHandler:
    @staticmethod
    def reads(bson: Dict) -> IrwinQueue:
        return IrwinQueue(
            id=bson['_id'],
            origin=bson['origin'])

    @staticmethod
    def writes(irwinQueue: IrwinQueue) -> Dict:
        return {
            '_id': irwinQueue.id,
            'origin': irwinQueue.origin,
            'date': datetime.now()
        }

class IrwinQueueDB(NamedTuple('IrwinQueueDB', [
        ('irwinQueueColl', Collection)
    ])):
    def write(self, irwinQueue: IrwinQueue):
        self.irwinQueueColl.update_one(
            {'_id': irwinQueue.id}, 
            {'$set': IrwinQueueBSONHandler.writes(irwinQueue)},
            upsert=True)


# Path: modules/queue/Origin.py
# def maxOrigin(a, b):
# 
# Path: modules/game/Game.py
# class Game(NamedTuple('Game', [
#         ('id', GameID),
#         ('white', PlayerID),
#         ('black', PlayerID),
#         ('pgn', List[str]),
#         ('emts', Opt[List[Emt]]),
#         ('analysis', Analysis)
#     ])):
# class GameBSONHandler:
# class GameDB(NamedTuple('GameDB', [
#         ('gameColl', Collection)
#     ])):
#     def fromDict(d: Dict):
#     def fromJson(json: Dict):
#     def toJson(self):
#     def playable(self):
#     def boardTensors(self, colour):
#     def boardTensorsByPlayerId(self, playerId: PlayerID, length: int = 60, safe: bool = True):
#     def tensor(self, playerId: PlayerID, length: int = 60, noisey: bool = False, safe: bool = True) -> Opt[GameTensor]:
#     def emtsByColour(self, colour: Colour, emts: Opt[List[int]] = None) -> List[Emt]:
#     def moveTensor(analysis: Analysis, emt: Emt, boardTensor: List[int], avgEmt: Number, colour: Colour) -> MoveTensor:
#     def nullBoardTensor():
#     def nullMoveTensor() -> MoveTensor:
#     def ply(moveNumber: int, colour: Colour) -> int:
#     def reads(bson: Dict) -> Game:
#     def writes(game: Game) -> Dict:
#     def byId(self, _id: GameID) -> Opt[Game]:
#     def byIds(self, ids: List[GameID]) -> List[Game]:
#     def byPlayerId(self, playerId: PlayerID) -> List[Game]:
#     def byPlayerIdAndAnalysed(self, playerId: PlayerID, analysed: bool = True) -> List[Game]:
#     def write(self, game: Game):
#     def writeMany(self, games: List[Game]):


# Path: modules/queue/IrwinQueue.py
from default_imports import *
from modules.queue.Origin import Origin
from modules.game.Game import PlayerID
from datetime import datetime
from pymongo.collection import Collection
import pymongo


IrwinQueue = NamedTuple('IrwinQueue', [
        ('id', PlayerID),
        ('origin', Origin)
    ])

class IrwinQueueBSONHandler:
    @staticmethod
    def reads(bson: Dict) -> IrwinQueue:
        return IrwinQueue(
            id=bson['_id'],
            origin=bson['origin'])

    @staticmethod
    def writes(irwinQueue: IrwinQueue) -> Dict:
        return {
            '_id': irwinQueue.id,
            'origin': irwinQueue.origin,
            'date': datetime.now()
        }

class IrwinQueueDB(NamedTuple('IrwinQueueDB', [
        ('irwinQueueColl', Collection)
    ])):
    def write(self, irwinQueue: IrwinQueue):
        self.irwinQueueColl.update_one(
            {'_id': irwinQueue.id}, 
            {'$set': IrwinQueueBSONHandler.writes(irwinQueue)},
            upsert=True)


    def removePlayerId(self, playerId: PlayerID):