import logging

import cv2
from PyQt5.QtCore import QThread


class DummyVideoCapture:
    def __init__(self, device):
        self.values = {}
        self.sim_imgs = None
        self.log = logging.getLogger(f"{self.__class__.__name__} ({id(self)}) (dummy)")
        self.log.debug(f"__init__({device!r})")

    def get(self, prop):
        val = self.values.get(prop, 0)
        self.log.debug(f"{self.__class__.__name__}.get() -> {val}")
        return val

    def set(self, prop, val):
        self.values[prop] = val
        self.log.debug(f"{self.__class__.__name__}.set({val}) -> {val}")

    def read(self):
        # self.log.debug(f"{self.__class__.__name__}.read()")
        if self.sim_imgs is None:
            return False, None
        else:
            img_path = next(self.sim_imgs)
            self.log.debug(f"loading image {img_path}")
            frame = cv2.cvtColor(cv2.imread(str(img_path)), cv2.COLOR_BGR2RGB)
            QThread.msleep(1000)
            return True, frame
