import sys
import os
sys.path.append(os.getcwd())    # noqa E402
from decorator import timer, debug, slow_down
import math
import random


PLUGINS = dict()


@timer
def waste_time(num):
    for _ in range(num):
        sum([i ** 2 for i in range(10000)])


@debug
def make_greeting(first_name, age: int):
    return f'Hello {first_name}, you are {age}!'


math.factorial = debug(math.factorial)


def approximate_e(terms):
    return sum(1 / math.factorial(n) for n in range(terms))


@slow_down
def countdown(num: int):
    if num < 1:
        print('Liftoff!')
    else:
        print(num)
        countdown(num - 1)


def register(func):
    """Register a function as a plug-in"""
    PLUGINS[func.__name__] = func
    return func


@register
def say_hello(name: str) -> str:
    return f'Hello {name}'


@register
def be_awesome(name: str) -> str:
    return f'Yo {name}, together we are awesome!'


def randomly_greet(name):
    greeter, greeter_func = random.choice(list(PLUGINS.items()))
    print(f'Using {greeter!r}')
    return greeter_func(name)
