from pydantic import BaseModel
from typing import Optional
import datetime

from pymysql import NULL

SECRET_KEY = "df2f77bd544240801a048bd4293afd8eeb7fff3cb7050e42c791db4b83ebadcd"
ALGORITHM = "HS256"


class Token(BaseModel):
    access_token: str
    token_type: str

class del_user(BaseModel):
    access_token: str
    del_name: str

class User(BaseModel):
    id: int
    username: str
    password: str
    changPwdTime: Optional[datetime.datetime] = None
    isAdmin: Optional[bool] = None
    isEnable: Optional[bool] = True
    updateTime: Optional[datetime.datetime] = None
    token: Optional[str] = None

class user_authority(BaseModel):
    ai_prediction_isView : int
    ai_prediction_isAdd : int
    ai_prediction_isEdit : int
    ai_prediction_isDel : int
    channel_isView : int
    channel_isAdd : int
    channel_isEdit : int
    channel_isDel : int
    device_isView : int
    device_isAdd : int
    device_isEdit : int
    device_isDel : int
    event_isView : int
    event_isAdd : int
    event_isEdit : int
    event_isDel : int
    index_isView : int
    index_isAdd : int
    index_isEdit : int
    index_isDel : int
    performance_isView : int
    performance_isAdd : int
    performance_isEdit : int
    performance_isDel : int
    record_isView : int
    record_isAdd : int
    record_isEdit : int
    record_isDel : int
    setting_device_isView : int
    setting_device_isAdd : int
    setting_device_isEdit : int
    setting_device_isDel : int
    setting_system_isView : int
    setting_system_isAdd : int
    setting_system_isEdit : int
    setting_system_isDel : int
    tower_isView : int
    tower_isAdd : int
    tower_isEdit : int
    tower_isDel : int
    ai_prediction_id:int
    channel_id:int
    device_id:int
    event_id:int
    index_id:int
    performance_id:int
    record_id:int
    setting_device_id:int
    setting_system_id:int
    tower_id:int
    role_id:str
    access_token: str
    def get_acl_from_module_name(self,module_name:str):
        result = {}
        exec("result['id'] = self.{}".format(module_name+'_id'))
        exec("result['isView'] = self.{}".format(module_name+'_isView'))
        exec("result['isAdd'] = self.{}".format(module_name+'_isAdd'))
        exec("result['isEdit'] = self.{}".format(module_name+'_isEdit'))
        exec("result['isDel'] = self.{}".format(module_name+'_isDel'))
        result["role_id"]= self.role_id
        result["module_id"]= module_name
        print(result)
        return result



# AuthJWT setting
class Settings(BaseModel):
    authjwt_secret_key: str = SECRET_KEY
    authjwt_token_location: set = {"cookies"}
    authjwt_cookie_secure: bool = False
    authjwt_cookie_csrf_protect: bool = True

class record_tower_data(BaseModel):
    hotTemp: float
    coldTempData1:float
    coldTempData2:float
    reducer:float
    total:float
    towernum:float
    fannum:float
    flowchange:float
    savewater:float
    fanchange:float
    saveelec:float
    count:float
    wetTemp:float
    count1:float
    staticPressure:float
    waterFlow:float


class record_dcs_data(BaseModel):
    hotTemp: float
    coldTemp:float
    fanMotorCur:float
    fanMotorSpeedFreq:float
    waterFlow:float

class record_diagnosis_data(BaseModel):
    DW_Unbalance: float
    DW_Bending:float
    DW_Misalignment:float
    DW_Loose:float
    DW_Whirl:float
    DW_Whip:float
    DW_InnerDamage:float
    DW_OuterDamage:float
    DW_BallDamage:float
    DW_AirGap:float
    DW_BrokenBars:float
    DW_PhaseProblem:float
    DW_GMisalignment:float
    DW_GBrokenTeeth:float
    DW_Gwear:float
    DW_GBending:float
    DW_GEccentricity:float
    vibration_id:float

class record_health_data(BaseModel):
    time_stamp:str
    CV_index:float
    Vrms:float
    Grms:float
    RPM:float 
    PeakToPeak:float
    MeanAbsolute:float
    Skewness:float
    Kurtosis:float
    WaveformFactor:float
    CrestFactor:float
    ImpulseFactor:float
    StandardDeviation:float
    MeanValue:float
    Maximum:float
    Minimum:float
    IQR:float
    vibration_id:str

class record_performance_data(BaseModel):
    creatTime:str
    deviceCode:str
    designWFR:float
    designHP:float
    designCurrent:float
    designHWT:float
    designCWT:float
    designWBT:float
    testWFR:float
    testBHP:float
    testCurrent:float
    testHWT:float
    testCWT:float
    testWBT:float
    testWindSpeed:float
    testMakeupWFR:float
    testMakeupCWT:float
    testCorrectCWT:float
    testCoolingRange:float
    resPredictRate:float
    resPredictWFR:float
    resCorrectedWFR:float
    resPerformance:float
    coolingRangeData:str
    coolingRangeChart:str
    waterFlowRateChart:str

class record_prediction_data(BaseModel):
    time_stamp:str
    valueType:str
    predictType:str
    timeInternal:int
    alarmValue:float
    calCount:int
    remainCount:int
    remark:str
    vibration_id:str

class record_prediction_upd_data(BaseModel):
    time_stamp:str
    valueType:str
    predictData:str
    vibration_id:str