from pycs.database.Result import Result


#pylint: disable=too-few-public-methods
class MediaBoundingBox:
    """
    A bounding box defined by it's upper left corner coordinates plus width and height. All those
    values are normalized. A label and a frame (for videos) are optional.
    """

    def __init__(self, result: Result):
        self.x = result.data['x']
        self.y = result.data['y']
        self.w = result.data['w']
        self.h = result.data['h']
        self.label = result.label if hasattr(self, 'label') else None
        self.frame = result.data['frame'] if 'frame' in result.data else None

    def serialize(self) -> dict:
        """
        serialize all object properties to a dict

        :return: dict
        """
        return dict({'type': 'bounding-box'}, **self.__dict__)