import store from '@/store';
import request from '@/config/request';
import { DeviceCommandModel } from '@/config/models';
import { isNotNull } from '@/services/utils-service';

const APICommandList = {
  getClocks() {
    const data = { deviceId: store.getters.deviceId };
    return request({ url: '/api/Command/CommandList', method: 'post', data });
  },
  setClocks(cmdValue) {
    const data = {
      deviceId: store.getters.deviceId,
      userId: store.getters.userId,
      serialNo: store.getters.serialNo,
      cmdCode: DeviceCommandModel.clock,
      cmdValue
    };
    return request({ url: '/api/Command/SendCommand', method: 'post', data });
  },
  getCmdValue(data, deviceCommandModel) {
    const result = data.filter(v => v.cmdCode === deviceCommandModel);
    return isNotNull(result) ? JSON.parse(result[0].cmdValue).Items : [];
  }
};

export default APICommandList;
