""" Code for wrapping the motion primitive action in an object. """
from __future__ import division
from __future__ import absolute_import

import attr
import numpy as np

from bc_gym_planning_env.utilities.serialize import Serializable


@attr.s(cmp=False)
class Action(Serializable):
    """ Object representing an 'action' - a motion primitive to execute in the environment """
    VERSION = 1
    command = attr.ib(type=np.ndarray)

    @classmethod
    def from_cmds(cls, wanted_linear_velocity_of_baselink, wanted_front_wheel_angle):
        return cls(command=np.array([wanted_linear_velocity_of_baselink, wanted_front_wheel_angle]))

    def __eq__(self, other):
        if not isinstance(other, Action):
            return False

        if (self.command != other.command).any():
            return False

        return True

    def __ne__(self, other):
        return not self.__eq__(other)

[(11, 'attr.s', 'attr.s', False, 'import attr\n'), (15, 'attr.ib', 'attr.ib', False, 'import attr\n'), (19, 'numpy.array', 'np.array', True, 'import numpy as np\n')]