/*
 * @Author: sjl
 * @Date: 2023-05-15 20:12:17
 * @Descripttion:
 */

import { defineStore } from 'pinia';
import { store } from '/@/store';
import {
  ligongGetMonitorDevices,
  ligongGetMonitorSensors,
  ligongGetMonitorChart,
  ligongGetMonitorPoints,
  ligongDeviceKind,
  ligongDeviceSensorOnline,
  ligongDeviceSensorOnliness,
  ligongDeviceSensor,
  ligongMonitorDataTop20,
  ligongGetVideoList,
  ligongCount,
  ligongResultCount,
  updateElevation,
  originCount,
  waterDevice,
  waterDeviceStatus,
  newest,
} from '/@/api/sys/ligong';

interface MonitorDevices {
  sideMenu: boolean;
}
export const useMonitorDevicesStore = defineStore({
  id: 'monitorDevices',
  state: (): MonitorDevices => ({
    sideMenu: true,
  }),
  getters: {
    getSideMenu(): boolean {
      return this.sideMenu;
    },
  },
  actions: {
    setSideMenu(): void {
      this.sideMenu = !this.sideMenu;
    },

    LiGongMonitorDevicesList(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongGetMonitorDevices(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          // ligongGetMonitorDevices(params).then((data) => {
          //   if (data.code == 200) resolve(data);
          // });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },

    originCount(params): Promise<UserInfo | null> {
      try {
        // const data = await originCount(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          originCount(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },
    waterDevice(params): Promise<UserInfo | null> {
      try {
        // const data = await waterDevice(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          // waterDevice(params).then((data) => {
          //   if (data.code == 200) resolve(data);
          // });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },
    waterDeviceStatus(params): Promise<UserInfo | null> {
      try {
        // const data = await waterDeviceStatus(params);
        // if (data.code == 200) {
        //   return data;
        // }
        // return new Promise((resolve, reject) => {
        //   waterDeviceStatus(params).then((data) => {
        //     if (data.code == 200) resolve(data);
        //   });
        // });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },
    newest(params): Promise<UserInfo | null> {
      try {
        // const data = await newest(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          newest(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },

    ligongCount(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongCount(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          ligongCount(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },
    ligongResultCount(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongResultCount(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          ligongResultCount(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },

    LigongGetVideoList(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongGetVideoList(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          ligongGetVideoList(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },

    LiGongMonitorSensorsList(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongGetMonitorSensors(params);
        // if (data.code == 200) {
        //   return data;
        // }
        // return new Promise((resolve, reject) => {
        //   ligongGetMonitorSensors(params).then((data) => {
        //     if (data.code == 200) resolve(data);
        //   });
        // });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },

    LiGongMonitorChart(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongGetMonitorChart(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          ligongGetMonitorChart(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },

    LiGongMonitorPoints(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongGetMonitorPoints(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          ligongGetMonitorPoints(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },

    LiGongDeviceKind(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongDeviceKind(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          ligongDeviceKind(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },

    LigongDeviceSensorOnline(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongDeviceSensorOnline(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          ligongDeviceSensorOnline(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },
    ligongDeviceSensorOnliness(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongDeviceSensorOnliness(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          ligongDeviceSensorOnliness(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },

    async updateElevation(params): Promise<UserInfo | null> {
      try {
        const data = await updateElevation(params);
        if (data.code == 200) {
          return data;
        }
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },

    LigongDeviceSensor(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongDeviceSensor(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          ligongDeviceSensor(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },

    /**
     * 实时监控20条
     */
    LiGongMonitorDataTop20(params): Promise<UserInfo | null> {
      try {
        // const data = await ligongMonitorDataTop20(params);
        // if (data.code == 200) {
        //   return data;
        // }
        return new Promise((resolve, reject) => {
          ligongMonitorDataTop20(params).then((data) => {
            if (data.code == 200) resolve(data);
          });
        });
      } catch (error) {
        console.log(error);
        return Promise.reject(error);
      }
    },
  },
});
// Need to be used outside the setup
export function useMonitorDevicesMapStoreOut() {
  return useMonitorDevicesStore(store);
}
