import uuid
import datetime as dt
from marshmallow import Schema, fields, post_load

from vrpmdvmonreq import VRPMDV_MonReq
from extensions.rt_service import rt_service as rts
from vrpmdvmonitoringState import VRPMDVMonitoringState

# class VRPMDV_MonReq:
#     def __init__(self, name , samplerate, sampleperiod, downtime, owner) :
#         self.name = name
#         self.samplerate = samplerate
#         self.sampleperiod = sampleperiod
#         self.downtime = downtime
#         self.owner = owner

class VRPMDV_Monitoring(VRPMDV_MonReq):

    def __init__(self, id, name , samplerate, sampleperiod, downtime, status, owner="None", created_at=dt.datetime.now()) :
        self.id =  id
        self.created_at = created_at
        self.rtservice = rts.RT_Service()
        super().__init__(name, samplerate, sampleperiod, downtime, owner, status)

    def createMonitoring(self) :
        if self.status != VRPMDVMonitoringState.OFF: 
            iscreated = self.rtservice.createMonitoring(str(self.id)) 
            if not iscreated :
                self.status = VRPMDVMonitoringState.OFF
            return True
        return False
    
    def deleteMonitoring(self) :
        isdeleted = self.rtservice.deleteMonitoring(str(self.id)) 
        if (isdeleted) :
            self.monstate = VRPMDVMonitoringState.OFF
            return True
        return False    
    
    def startMonitoring(self) :
        isstarted = self.rtservice.setMonitoringState(str(self.id), VRPMDVMonitoringState.started) 
        if (isstarted) :
            self.monstate = VRPMDVMonitoringState.STARTED
            return True
        return False        
    
    def stopMonitoring(self) :
        isstopped = self.rtservice.setMonitoringState(str(self.id), VRPMDVMonitoringState.stopped) 
        if (isstopped) :
            self.monstate = VRPMDVMonitoringState.STOPPED
            return True
        return False            
    
    def setStatus(self, status) :
        isStatusSet = self.rtservice.setMonitoringStatus(str(self.id), status) 
        if (isStatusSet) :
            self.status = status
            return True
        return False            