import math

from core.chat_blob import ChatBlob
from core.command_param_types import Int
from core.db import DB
from core.decorators import instance, command
from core.dict_object import DictObject
from core.text import Text


@instance()
class OverequippedController:
    def inject(self, registry):
        self.db: DB = registry.get_instance("db")
        self.text: Text = registry.get_instance("text")

    @command(command="oe", params=[Int("skill_level")], access_level="member",
             description="Show the current time in every timezone")
    def oe_command(self, _, skill_level):
        oe = self.get_oe_vals(skill_level)

        blob = f"With a skill requirement of <highlight>{skill_level}</highlight>, you will be\n"
        blob += f"Out of OE: <highlight>{oe.oe100low}</highlight> or higher\n"
        blob += f"75%: <highlight>{oe.oe75low}</highlight> to <highlight>{oe.oe100low - 1}</highlight>\n"
        blob += f"50%: <highlight>{oe.oe50low}</highlight> to <highlight>{oe.oe75low - 1}</highlight>\n"
        blob += f"25%: <highlight>{oe.oe25low}</highlight> to <highlight>{oe.oe50low - 1}</highlight>\n"
        blob += f"0%: <highlight>{oe.oe25low - 1}</highlight> or lower\n\n"

        blob += f"With a personal skill of <highlight>{skill_level}</highlight>, you can use up to\n"
        blob += f"Out of OE: <highlight>{oe.oe100}</highlight> or lower\n"
        blob += f"75%: <highlight>{oe.oe100 + 1}</highlight> to <highlight>{oe.oe75}</highlight>\n"
        blob += f"50%: <highlight>{oe.oe75 + 1}</highlight> to <highlight>{oe.oe50}</highlight>\n"
        blob += f"25%: <highlight>{oe.oe50 + 1}</highlight> to <highlight>{oe.oe25}</highlight>\n"
        blob += f"0%: <highlight>{oe.oe25 - 1}</highlight> or higher\n"

        return ChatBlob("%d - %d - %d" % (oe.oe100low, skill_level, oe.oe100), blob)

    def get_oe_vals(self, skill_level):
        return DictObject({
            "oe100": int(math.floor(skill_level / 0.8)),
            "oe100low": int(math.floor(skill_level * 0.8)),
            "oe75": int(math.floor(skill_level / 0.6)),
            "oe75low": int(math.floor(skill_level * 0.6)),
            "oe50": int(math.floor(skill_level / 0.4)),
            "oe50low": int(math.floor(skill_level * 0.4)),
            "oe25": int(math.floor(skill_level / 0.2)),
            "oe25low": int(math.floor(skill_level * 0.2))})
