from enum import Enum


class VideoContainerType(Enum):
    MP4 = 'mp4'
    MOV = 'mov'


class VideoCodecType(Enum):
    H264 = 'h264'
    H265 = 'h265'


class CameraType(Enum):
    ESP32 = 'esp32'
    XMEYE = 'xmeye'
    HIKVISION_264 = 'hik_264'
    HIKVISION_265 = 'hik_265'

    def get_channel_url(self, channel: int) -> str:
        if channel not in (1, 2):
            raise ValueError(f'channel {channel} is invalid')
        if channel == 1:
            return ''
        elif channel == 2:
            if self.is_hikvision():
                return '/Streaming/Channels/2'
            elif self.is_xmeye():
                return '/?stream=1.sdp'
            else:
                raise ValueError(f'unsupported camera type {self.value}')

    def get_codec(self, channel: int) -> VideoCodecType:
        if channel == 1:
            return VideoCodecType.H264 if self == CameraType.HIKVISION_264 else VideoCodecType.H265
        elif channel == 2:
            return VideoCodecType.H265 if self == CameraType.XMEYE else VideoCodecType.H264
        else:
            raise ValueError(f'unexpected channel {channel}')

    def get_container(self) -> VideoContainerType:
        return VideoContainerType.MP4 if self.get_codec(1) == VideoCodecType.H264 else VideoContainerType.MOV

    def is_hikvision(self) -> bool:
        return self in (CameraType.HIKVISION_264, CameraType.HIKVISION_265)

    def is_xmeye(self) -> bool:
        return self == CameraType.XMEYE


class TimeFilterType(Enum):
    FIX = 'fix'
    MOTION = 'motion'
    MOTION_START = 'motion_start'


class TelegramLinkType(Enum):
    FRAGMENT = 'fragment'
    ORIGINAL_FILE = 'original_file'


class CaptureType(Enum):
    HLS = 'hls'
    RECORD = 'record'
