import { getAllNotice,getAllDevice,saveDevice,delDevice,getDeviceNum,getNewAddBug,importUserDeviceListExcel,
  getUserDevice,saveUserDevice,getTargetKeys,getNewAdd,importUserListExcel,getDeviceDetails } from '@/services/communityNotice';
import { getRegion,getRegionList } from '@/services/region';

export default{
  namespace: 'communityNoticeModel',
  state: {
    data: [],
  },
  effects: {



    *getAllNotice({callback,payload},{ call, put }) {
      const response = yield call(getAllNotice,payload);
      yield put({
        type: "getAll",
      });
      if(callback) callback(response);
    },
    *getAllDevice({callback,payload},{ call, put }) {
      const response = yield call(getAllDevice,payload);
      yield put({
        type: "getAll",
      });
      if(callback) callback(response);
    },
    *getRegion({callback,payload},{ call, put }) {
      const response = yield call(getRegion,payload);
      yield put({
        type: "getRegions",
      });
      if(callback) callback(response);
    },
    *saveDevice({callback,payload},{ call, put }) {
      const response = yield call(saveDevice,payload);
      yield put({
        type: "save",
      });
      if(callback) callback(response);
    },
    *delDevice({callback,payload},{ call, put }) {
      const response = yield call(delDevice,payload);
      yield put({
        type: "del",
      });
      if(callback) callback(response);
    },
    *getRegionList({callback,payload},{ call, put }) {
      const response = yield call(getRegionList,payload);
      yield put({
        type: "regionList",
      });
      if(callback) callback(response);
    },
    *getDeviceNum({callback,payload},{ call, put }) {
      const response = yield call(getDeviceNum,payload);
      yield put({
        type: "num",
      });
      if(callback) callback(response);
    },
    *getUserDevice({callback,payload},{ call, put }) {
      const response = yield call(getUserDevice,payload);
      yield put({
        type: "userDevice",
      });
      if(callback) callback(response);
    },
    *saveUserDevice({callback,payload},{ call, put }) {
      const response = yield call(saveUserDevice,payload);
      yield put({
        type: "userDeviceSave",
      });
      if(callback) callback(response);
    },
    *getTargetKeys({callback,payload},{ call, put }) {
      const response = yield call(getTargetKeys,payload);
      yield put({
        type: "targetKeys",
      });
      if(callback) callback(response);
    },
    *getNewAdd({callback,payload},{ call, put }) {
      const response = yield call(getNewAdd,payload);
      yield put({
        type: "newAdd",
      });
      if(callback) callback(response);
    },
    *getNewAddBug({callback,payload},{ call, put }) {
      const response = yield call(getNewAddBug,payload);
      yield put({
        type: "newAddBug",
      });
      if(callback) callback(response);
    },
    *importUserListExcel({callback,payload},{ call, put }) {
      const response = yield call(importUserListExcel,payload);
      yield put({
        type: "importListExcel",
      });
      if(callback) callback(response);
    },
    *importUserDeviceListExcel({callback,payload},{ call, put }) {
      const response = yield call(importUserDeviceListExcel,payload);
      yield put({
        type: "importDeviceListExcel",
      });
      if(callback) callback(response);
    },
    *getDeviceDetails({callback,payload},{ call, put }) {
      const response = yield call(getDeviceDetails,payload);
      yield put({
        type: "deviceDetails",
      });
      if(callback) callback(response);
    },
  },
  reducers: {
    getAll(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    getRegions(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    save(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    del(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    regionList(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    num(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    userDevice(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    userDeviceSave(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    targetKeys(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    newAdd(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    newAddBug(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    importListExcel(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    importDeviceListExcel(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    deviceDetails(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
  },
};


