import {getAllSites} from '@/api/ems/zddt'
import {getAlarmDetailList, getSiteAllDeviceCategory} from '@/api/ems/dzjk'

const ems = {
    state: {
        dzjkAlarmLighting: false,//单站监控 告警统计红点标志
        zdList: [],
        zdDeviceCategoryOptions: {},//站点各个站点包含的设备种类 {021_DDS_01:["BATTERY","CLUSTER","STACK", "DH", "AMMETER", "PCS", "XF"],021_DDS_02:[]...}
        workStatusOptions: {'0': '正常', '1': '异常', '2': '停止'},//工作状态
        deviceStatusOptions: {'0': '离线', '1': '待机', '2': '运行', '3': '故障', '4': '停机'},//设备状态
        gridStatusOptions: {'0': '并网', '1': '未并网'},//并网状态
        controlModeOptions: {'0': '远程', '1': '本地'},//控制模式
        warnOptions: {0: '正常', 1: '中断', 2: '不在线', 3: '异常'},//告警状态
        communicationStatusOptions: {'0': '正常', '1': '通讯中断', '2': '异常'},//通讯状态
        workModeOptions: {'0': '正常', '1': '停止'},//工作模式
        alarmLevelOptions: {'A': '提示', 'B': '一般', 'C': '严重', 'D': '紧急'},//告警等级
        alarmStatusOptions: {'0': '待处理', '1': '已处理', '2': '处理中'},//告警状态
        deviceTypeOptions: {'TCP': 'TCP', 'RTU': 'RTU'},//设备类型
        ticketStatusOptions: {1: '待处理', 2: '处理中', 3: '已处理'},//工单处理状态
        strategyStatusOptions: {'0': '未启用', '1': '已运行', '2': '已暂停', '3': '禁用', '4': '删除'},//策略状态
        chargeStatusOptions: {'1': '充电', '2': '待机'},//冲放状态
        comparisonOperatorOptions: {'>': '>', '<': '<', '=': '=', '>=': '>=', '<=': '<='},
        relationWithPoint: {'||': '||', '&&': '&&'}
    },
    mutations: {
        SET_ZD_LIST(state, list) {
            state.zdList = list || []
        },
        SET_DZJK_ALARM_LIGHTING(state, status) {
            state.dzjkAlarmLighting = status
        },
        SET_ZD_DEVICE_CATEGORY_OPTIONS(state, {siteId, data}) {
            state.zdDeviceCategoryOptions = Object.assign({}, state.zdDeviceCategoryOptions, {[siteId]: data})
        }
    },
    actions: {
        getZdList({commit, state}) {
            if (state.zdList.length === 0) {
                getAllSites().then(response => {
                    commit('SET_ZD_LIST', response?.data || [])
                    console.log('store action getZdList 获取站点数据', state.zdList)
                })
            }
        },
        //查询站点的所有待处理0的告警 存在展示红点标志
        getSiteAlarmNum({state, commit}, siteId) {
            getAlarmDetailList({
                status: 0,
                siteId,
                pageSize: 10,
                pageNum: 1,
                deviceId: '',
                alarmLevel: '',
                alarmStartTime: '',
                alarmEndTime: ''
            }).then(response => {
                commit('SET_DZJK_ALARM_LIGHTING', !!response?.total || false)
            })
        },
        getSiteDeviceCategory({state, commit}, siteId) {
            getSiteAllDeviceCategory(siteId).then(response => {
                let data = response?.data || [];
                data.unshift('SSYX');
                commit('SET_ZD_DEVICE_CATEGORY_OPTIONS', {siteId, data})
            })
        }

    }
}

export default ems
