from threading import Thread
import logging

from enum import Enum


class Cmd(Enum):
    TYPE = 1
    DATA = 2


class Rslt(Enum):
    SYST = 'systole'
    DIAS = 'diastole'
    INST_HR = 'instantaneous HR'
    AVG_HR = 'average HR'


class FeatureDetection(Thread):

    def __init__(self, commands, results):
        Thread.__init__(self, daemon=True)

        self.commands = commands
        self.results = results

        self.feature_detector = None

    def run(self):

        # Really while True
        while True:
            cmd = self.commands.get()

            # Command switch case
            if cmd[0] == Cmd.TYPE:
                if cmd[1] == 'ECG':
                    # self.feature_detector = EcgDetector(self.results)
                    logging.warning('ECG detector is not yet implemented.')
                    pass
                elif cmd[1] == 'PPG':
                    from ppg.ppg_detector import PpgDetector
                    self.feature_detector = PpgDetector(self.results)
                else:
                    logging.warning('Unknown detector: {}. (values: ECG orPPG)'
                                    .format(cmd[1]))
            if cmd[0] == Cmd.DATA:
                if self.feature_detector is not None:
                    for x in cmd[1]:
                        self.feature_detector.append(x)
                else:
                    logging.warning('Type of data should be sent once' +
                                    'before sending data.')

            self.commands.task_done()
