# Path: navigation/MathUtils.py
# class MathUtils:
#     @staticmethod
#     def remap(value: int, from_low: int, from_high: int, to_low: int, to_high: int) -> int:
#         return int((value - from_low) * (to_high - to_low) / (from_high - from_low) + to_low)


from navigation.MathUtils import MathUtils


class RobotSerialCommandsConverter:
    MAX_ANGLE = 180
    MIN_ANGLE = 0
    MOTOR_COMMAND = 'M:{0}:{1}'
    LIGHT_COMMAND = 'L:{0}'
    MESSAGE_TERMINATOR = ';'
    POWER_LIMITS = {'forward': {'max': 50, 'min': 0}, 'backward': {'max': -50, 'min': 0}}
    DIRECTION_LIMITS = {'right': 50, 'left': -50}

    def get_steer_command(self, angle: int, percent_power: int, forward: bool) -> str:
        direction = self.__get_converted_direction(angle)
        power = self.__get_converted_power(percent_power, forward)
        return self.MOTOR_COMMAND.format(direction, power)

    def get_lights_command(self, state: bool) -> str:
        literal_state = {True: '1', False: '0'}
        return self.LIGHT_COMMAND.format(literal_state[state])

    def __get_converted_power(self, percent_power: int, forward: bool) -> str:
        power_limits_key = {True: 'forward', False: 'backward'}[forward]
        return str(MathUtils.remap(
                percent_power, 0, 100,
                self.POWER_LIMITS[power_limits_key]['min'], self.POWER_LIMITS[power_limits_key]['max']))

    def __get_converted_direction(self, angle: int) -> int:

# Path: navigation/MathUtils.py
# class MathUtils:
#     @staticmethod
#     def remap(value: int, from_low: int, from_high: int, to_low: int, to_high: int) -> int:
#         return int((value - from_low) * (to_high - to_low) / (from_high - from_low) + to_low)


# Path: navigation/RobotSerialCommandsConverter.py
from navigation.MathUtils import MathUtils



class RobotSerialCommandsConverter:
    MAX_ANGLE = 180
    MIN_ANGLE = 0
    MOTOR_COMMAND = 'M:{0}:{1}'
    LIGHT_COMMAND = 'L:{0}'
    MESSAGE_TERMINATOR = ';'
    POWER_LIMITS = {'forward': {'max': 50, 'min': 0}, 'backward': {'max': -50, 'min': 0}}
    DIRECTION_LIMITS = {'right': 50, 'left': -50}

    def get_steer_command(self, angle: int, percent_power: int, forward: bool) -> str:
        direction = self.__get_converted_direction(angle)
        power = self.__get_converted_power(percent_power, forward)
        return self.MOTOR_COMMAND.format(direction, power)

    def get_lights_command(self, state: bool) -> str:
        literal_state = {True: '1', False: '0'}
        return self.LIGHT_COMMAND.format(literal_state[state])

    def __get_converted_power(self, percent_power: int, forward: bool) -> str:
        power_limits_key = {True: 'forward', False: 'backward'}[forward]
        return str(MathUtils.remap(
                percent_power, 0, 100,
                self.POWER_LIMITS[power_limits_key]['min'], self.POWER_LIMITS[power_limits_key]['max']))

    def __get_converted_direction(self, angle: int) -> int:

        return MathUtils.remap(angle, self.MIN_ANGLE, self.MAX_ANGLE,