from .timing import Timing
from .color_info import ColorInfo


class VideoMode:

    """

    Class `VideoMode` combines information about `Timing` and `ColorInfo`.

    """

    def __init__(self, timing: Timing = Timing(), color_info: ColorInfo = ColorInfo()):
        self.timing = timing
        self.color_info = color_info

    def __str__(self):
        return f"{self.timing.frame_rate / 1000:03} " \
               f"{self.timing.htotal} {self.timing.hstart} " \
               f"{self.timing.hactive} {self.timing.hswidth:+} " \
               f"{self.timing.vtotal} {self.timing.vstart} " \
               f"{self.timing.vactive} {self.timing.vswidth:+} " \
               f"{self.color_info.color_format.name}/" \
               f"{self.color_info.colorimetry.name}/" \
               f"{self.color_info.dynamic_range.name} {self.color_info.bpc}"

    def __eq__(self, other):
        return self.timing == other.timing and self.color_info == other.color_info

    def is_valid(self) -> bool:
        """

        Check that `Timing` and `ColorInfo` of Video mode is valid.

        Returns:
            object of bool type - Video mode valid or not
        """
        return self.timing.is_valid() and self.color_info.is_valid()

    @property
    def bit_rate(self) -> float:
        """

        Returns calculated bit rate required for this video mode in Gbps. 0 if video mode is not valid

        Returns:
            object of float type
        """
        if self.is_valid():
            return round(self.timing.pixel_clock * self.color_info.bpp / 1000.0, 3)
        else:
            return 0.0
