# Path: modules/queue/Env.py
# class Env:
#     def __init__(self, config: ConfigWrapper, db: Collection):
#         self.db = db
# 
#         self.engineQueueDB = EngineQueueDB(db[config['queue coll engine']])
#         self.irwinQueueDB = IrwinQueueDB(db[config['queue coll irwin']])
# 
# Path: modules/queue/EngineQueue.py
# class EngineQueue(NamedTuple('EngineQueue', [
#         ('id', EngineQueueID), # same as player ID
#         ('origin', Origin),
#         ('requiredGameIds', List[GameID]), # games that must be analysed
#         ('precedence', Precedence),
#         ('completed', bool),
#         ('owner', AuthID),
#         ('date', datetime)
#     ])):
# class EngineQueueBSONHandler:
# class EngineQueueDB(NamedTuple('EngineQueueDB', [
#         ('engineQueueColl', Collection)
#     ])):
#     def new(playerId: PlayerID, origin: Origin, gamesAndPredictions: List[Tuple[Game, int]]):
#     def complete(self):
#     def merge(engineQueueA, engineQueueB):
#     def reads(bson: Dict) -> EngineQueue:
#     def writes(engineQueue: EngineQueue) -> Dict:
#     def write(self, engineQueue: EngineQueue):
#     def inProgress(self) -> List[EngineQueue]:
#     def byId(self, _id: EngineQueueID) -> Opt[EngineQueue]:
#     def byPlayerId(self, playerId: str) -> Opt[EngineQueue]:
#     def complete(self, engineQueue: EngineQueue):
#     def updateComplete(self, _id: EngineQueueID, complete: bool):
#     def removePlayerId(self, playerId: PlayerID):
#     def exists(self, playerId: PlayerID) -> bool:
#     def owned(self, playerId: PlayerID) -> bool:
#     def oldest(self) -> Opt[EngineQueue]:
#     def nextUnprocessed(self, name: AuthID) -> Opt[EngineQueue]:
#     def top(self, amount: int = 20) -> List[EngineQueue]:
# 
# Path: modules/game/Player.py
# class Player(NamedTuple('Player', [
#     ('id', 'PlayerID'),
#     ('titled', bool),
#     ('engine', bool),
#     ('gamesPlayed', int)])):
# class PlayerBSONHandler:
# class PlayerDB(NamedTuple('PlayerDB', [
#         ('playerColl', 'Collection')
#     ])):
#     def fromJson(userData: Dict):
#     def reads(bson: Dict) -> Player:
#     def writes(player: Player) -> Dict:
#     def byId(self, playerId: PlayerID) -> Opt[Player]:
#     def byPlayerId(self, playerId: PlayerID) -> Opt[Player]:
#     def unmarkedByUserIds(self, playerIds: List[PlayerID]) -> List[Player]:
#     def engineSample(self, engine: bool, size: int) -> List[Player]:
#     def oldestNonEngine(self) -> Opt[Player]:
#     def byEngine(self, engine: bool = True) -> List[Player]:
#     def all(self) -> List[Player]:
#     def write(self, player: Player):
# 
# Path: modules/auth/Auth.py
# class Auth(NamedTuple('Auth', [('env', Env)])):
#     def loginUser(self, username: Username, password: Password) -> Tuple[Opt[User], Authorised]:
#     def registerUser(self, name: Username, password: Password, privs: List[Priv] = []) -> Opt[User]:
#     def authoriseTokenId(self, tokenId: TokenID, priv: Priv) -> Tuple[Opt[Token], Authorised]:
#     def authoriseUser(self, username: Username, password: Password, priv: Priv) -> Tuple[Opt[User], Authorised]:
#     def authoriseRequest(self, req: Opt[Dict], priv: Priv) -> Tuple[Opt[Authable], Authorised]:
#     def authoriseRoute(self, priv: Priv):
#         def decorator(func):
#             def wrapper(*args, **kwargs):


from default_imports import *
from modules.queue.Env import Env
from modules.queue.EngineQueue import EngineQueue, EngineQueueID
from modules.game.Player import PlayerID
from modules.auth.Auth import Authable



class Queue(NamedTuple('Queue', [('env', Env)])):
    def nextEngineAnalysis(self, id: EngineQueueID) -> Opt[EngineQueue]:
        return self.env.engineQueueDB.nextUnprocessed(id)


# Path: modules/queue/Env.py
# class Env:
#     def __init__(self, config: ConfigWrapper, db: Collection):
#         self.db = db
# 
#         self.engineQueueDB = EngineQueueDB(db[config['queue coll engine']])
#         self.irwinQueueDB = IrwinQueueDB(db[config['queue coll irwin']])
# 
# Path: modules/queue/EngineQueue.py
# class EngineQueue(NamedTuple('EngineQueue', [
#         ('id', EngineQueueID), # same as player ID
#         ('origin', Origin),
#         ('requiredGameIds', List[GameID]), # games that must be analysed
#         ('precedence', Precedence),
#         ('completed', bool),
#         ('owner', AuthID),
#         ('date', datetime)
#     ])):
# class EngineQueueBSONHandler:
# class EngineQueueDB(NamedTuple('EngineQueueDB', [
#         ('engineQueueColl', Collection)
#     ])):
#     def new(playerId: PlayerID, origin: Origin, gamesAndPredictions: List[Tuple[Game, int]]):
#     def complete(self):
#     def merge(engineQueueA, engineQueueB):
#     def reads(bson: Dict) -> EngineQueue:
#     def writes(engineQueue: EngineQueue) -> Dict:
#     def write(self, engineQueue: EngineQueue):
#     def inProgress(self) -> List[EngineQueue]:
#     def byId(self, _id: EngineQueueID) -> Opt[EngineQueue]:
#     def byPlayerId(self, playerId: str) -> Opt[EngineQueue]:
#     def complete(self, engineQueue: EngineQueue):
#     def updateComplete(self, _id: EngineQueueID, complete: bool):
#     def removePlayerId(self, playerId: PlayerID):
#     def exists(self, playerId: PlayerID) -> bool:
#     def owned(self, playerId: PlayerID) -> bool:
#     def oldest(self) -> Opt[EngineQueue]:
#     def nextUnprocessed(self, name: AuthID) -> Opt[EngineQueue]:
#     def top(self, amount: int = 20) -> List[EngineQueue]:
# 
# Path: modules/game/Player.py
# class Player(NamedTuple('Player', [
#     ('id', 'PlayerID'),
#     ('titled', bool),
#     ('engine', bool),
#     ('gamesPlayed', int)])):
# class PlayerBSONHandler:
# class PlayerDB(NamedTuple('PlayerDB', [
#         ('playerColl', 'Collection')
#     ])):
#     def fromJson(userData: Dict):
#     def reads(bson: Dict) -> Player:
#     def writes(player: Player) -> Dict:
#     def byId(self, playerId: PlayerID) -> Opt[Player]:
#     def byPlayerId(self, playerId: PlayerID) -> Opt[Player]:
#     def unmarkedByUserIds(self, playerIds: List[PlayerID]) -> List[Player]:
#     def engineSample(self, engine: bool, size: int) -> List[Player]:
#     def oldestNonEngine(self) -> Opt[Player]:
#     def byEngine(self, engine: bool = True) -> List[Player]:
#     def all(self) -> List[Player]:
#     def write(self, player: Player):
# 
# Path: modules/auth/Auth.py
# class Auth(NamedTuple('Auth', [('env', Env)])):
#     def loginUser(self, username: Username, password: Password) -> Tuple[Opt[User], Authorised]:
#     def registerUser(self, name: Username, password: Password, privs: List[Priv] = []) -> Opt[User]:
#     def authoriseTokenId(self, tokenId: TokenID, priv: Priv) -> Tuple[Opt[Token], Authorised]:
#     def authoriseUser(self, username: Username, password: Password, priv: Priv) -> Tuple[Opt[User], Authorised]:
#     def authoriseRequest(self, req: Opt[Dict], priv: Priv) -> Tuple[Opt[Authable], Authorised]:
#     def authoriseRoute(self, priv: Priv):
#         def decorator(func):
#             def wrapper(*args, **kwargs):


# Path: modules/queue/Queue.py
from default_imports import *
from modules.queue.Env import Env
from modules.queue.EngineQueue import EngineQueue, EngineQueueID
from modules.game.Player import PlayerID
from modules.auth.Auth import Authable




class Queue(NamedTuple('Queue', [('env', Env)])):
    def nextEngineAnalysis(self, id: EngineQueueID) -> Opt[EngineQueue]:
        return self.env.engineQueueDB.nextUnprocessed(id)


    def completeEngineAnalysis(self, _id: EngineQueueID):