# Path: mugen/constants.py
# TIME_FORMAT = Union[float, Tuple[int, float], Tuple[int, int, float], str]
# 
# class Color(str, Enum):
#     BLACK = "black"
#     WHITE = "white"
# 
#     def hex_code(self):
#         if self.value == self.BLACK:
#             return "#000000"
#         elif self.value == self.WHITE:
#             return "#ffffff"
#         else:
#             raise ValueError(f"No Hex code defined for {self}")
# 
# Path: mugen/exceptions.py
# class ParameterError(MugenError):
#     """
#     Exception class for mal-formed inputs
#     """
# 
#     pass
# 
# Path: mugen/utilities/general.py
# def preprocess_args(func: Callable, variable_names: List[str]):
#     """
#     Applies function to variables in variable_names before launching the function
#     """
# 
#     def wrapper(f, *a, **kw):
#         func_code = f.__code__
# 
#         names = func_code.co_varnames
#         new_a = [
#             func(arg) if (name in variable_names) else arg
#             for (arg, name) in zip(a, names)
#         ]
#         new_kw = {k: func(v) if k in variable_names else v for (k, v) in kw.items()}
#         return f(*new_a, **new_kw)
# 
#     return decorator.decorator(wrapper)


import re
from fractions import Fraction
from typing import List
from mugen.constants import TIME_FORMAT, Color
from mugen.exceptions import ParameterError
from mugen.utilities.general import preprocess_args


def hex_to_rgb(hex_value) -> List[int]:
    """Return [red, green, blue] for the color given as #rrggbb."""
    hex_value = hex_value.lstrip("#")
    len_hex_value = len(hex_value)
    return [
        int(hex_value[i : i + len_hex_value // 3], 16)
        for i in range(0, len_hex_value, len_hex_value // 3)
    ]


def color_to_hex_code(color):
    if color.startswith("#"):
        return color
    else:
        return Color(color).hex_code()


def convert_float_to_fraction(*variable_names: str):
    """
    Decorator to convert variables from floats to fractions
    """
    return preprocess_args(float_to_fraction, *variable_names)


def convert_time_to_seconds(*variable_names: str):
    """
    Decorator to convert variables from TIME_FORMAT to seconds
    """

# Path: mugen/constants.py
# TIME_FORMAT = Union[float, Tuple[int, float], Tuple[int, int, float], str]
# 
# class Color(str, Enum):
#     BLACK = "black"
#     WHITE = "white"
# 
#     def hex_code(self):
#         if self.value == self.BLACK:
#             return "#000000"
#         elif self.value == self.WHITE:
#             return "#ffffff"
#         else:
#             raise ValueError(f"No Hex code defined for {self}")
# 
# Path: mugen/exceptions.py
# class ParameterError(MugenError):
#     """
#     Exception class for mal-formed inputs
#     """
# 
#     pass
# 
# Path: mugen/utilities/general.py
# def preprocess_args(func: Callable, variable_names: List[str]):
#     """
#     Applies function to variables in variable_names before launching the function
#     """
# 
#     def wrapper(f, *a, **kw):
#         func_code = f.__code__
# 
#         names = func_code.co_varnames
#         new_a = [
#             func(arg) if (name in variable_names) else arg
#             for (arg, name) in zip(a, names)
#         ]
#         new_kw = {k: func(v) if k in variable_names else v for (k, v) in kw.items()}
#         return f(*new_a, **new_kw)
# 
#     return decorator.decorator(wrapper)


# Path: mugen/utilities/conversion.py
import re
from fractions import Fraction
from typing import List
from mugen.constants import TIME_FORMAT, Color
from mugen.exceptions import ParameterError
from mugen.utilities.general import preprocess_args



def hex_to_rgb(hex_value) -> List[int]:
    """Return [red, green, blue] for the color given as #rrggbb."""
    hex_value = hex_value.lstrip("#")
    len_hex_value = len(hex_value)
    return [
        int(hex_value[i : i + len_hex_value // 3], 16)
        for i in range(0, len_hex_value, len_hex_value // 3)
    ]


def color_to_hex_code(color):
    if color.startswith("#"):
        return color
    else:
        return Color(color).hex_code()


def convert_float_to_fraction(*variable_names: str):
    """
    Decorator to convert variables from floats to fractions
    """
    return preprocess_args(float_to_fraction, *variable_names)


def convert_time_to_seconds(*variable_names: str):
    """
    Decorator to convert variables from TIME_FORMAT to seconds
    """

    return preprocess_args(time_to_seconds, *variable_names)