# Path: webservice/service_func.py
# class func_error(Exception):
# class service_func:
# class default_func(service_func):
#     def __init__(self, message):
#     def __str__(self):
#     def __init__(self, func_path):
#     def check_server_key(self, args, server):
#     def init(self):
#     def execute(self, args, server):
#     def answer(self):
#     def get_meta(self):
#     def __init__(self, functions):
#     def answer(self):


from ..service_func import service_func, func_error, meta_arg
import random
        key = args["key"]
        category = int(args["category"])
        rank = int(args["rank"])
        team = int(args["team"])

        if server.key == key:
            cat = server.game_data.get_category(category)

            if cat is not None:
                if cat.ranks_available[rank]:
                    if server.game_data.current_question is None:
                        pool = []
                        for q in cat.questions:
                            if q.rank == rank and not q.asked:
                                pool.append(q)

                        if len(pool) > 0:
                            q_i = random.randint(0, len(pool)-1)
                            self.question = pool[q_i]
                            self.question.asked = True
                            self.points = server.game_data.points_table.points[self.question.rank]
                            server.game_data.ask_question(self.question, team)
                            cat.ranks_available[rank] = False
                        else:
                            raise func_error("No more question in this category with this rank")
                    else:
                        raise func_error("A question is already asked and waiting for an answer")
                else:
                    raise func_error("You can't ask anymore question with this rank and category")
            else:

# Path: webservice/service_func.py
# class func_error(Exception):
# class service_func:
# class default_func(service_func):
#     def __init__(self, message):
#     def __str__(self):
#     def __init__(self, func_path):
#     def check_server_key(self, args, server):
#     def init(self):
#     def execute(self, args, server):
#     def answer(self):
#     def get_meta(self):
#     def __init__(self, functions):
#     def answer(self):


# Path: webservice/funcs/ask_question.py
from ..service_func import service_func, func_error, meta_arg
import random

        key = args["key"]
        category = int(args["category"])
        rank = int(args["rank"])
        team = int(args["team"])

        if server.key == key:
            cat = server.game_data.get_category(category)

            if cat is not None:
                if cat.ranks_available[rank]:
                    if server.game_data.current_question is None:
                        pool = []
                        for q in cat.questions:
                            if q.rank == rank and not q.asked:
                                pool.append(q)

                        if len(pool) > 0:
                            q_i = random.randint(0, len(pool)-1)
                            self.question = pool[q_i]
                            self.question.asked = True
                            self.points = server.game_data.points_table.points[self.question.rank]
                            server.game_data.ask_question(self.question, team)
                            cat.ranks_available[rank] = False
                        else:
                            raise func_error("No more question in this category with this rank")
                    else:
                        raise func_error("A question is already asked and waiting for an answer")
                else:
                    raise func_error("You can't ask anymore question with this rank and category")
            else:

                raise func_error("Invalid category")