import random as rand

import utils


class PictographAuth:
    PICTOGRAPHS = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]  # noqa: RUF012

    def __init__(self, key):
        utils.check_if_type(key, list, name="key")
        self.key = key

    def login(self):
        yield from self._get_grids()

    def authencate(self, chosen):
        utils.check_if_type(chosen, list, name="chosen pictographs")
        if sorted(chosen) != sorted(self.key):
            raise Exception("Incorrect pictographs")  # noqa: TRY002

    def _get_grids(self, decoys=8):
        return [utils.shuffle(self._get_decoys(decoys) + [graph]) for graph in utils.shuffle(self.key)]

    def _get_decoys(self, num):
        utils.check_if_type(num, list, name="number of decoys")
        return rand.sample(sorted(set(PictographAuth.PICTOGRAPHS) - set(self.key)), num)

class AuthInterface:
    def __init__(self):
        self.introduce()
        self.init_auth()
        self.loop()

    def introduce(self):
        print("""
        Welcome to Pictograph Authencation
        
        A tool to use for practicing cracking pictograph MFA
        
        Pictograph set is """, end="")
        print(PictographAuth.PICTOGRAPHS)
        print()

    def init_auth(self):
        pass

    def loop(self):
        pass

if __name__ == "__main__":
    AuthInterface()