import { getVisitorRecord,getAdvertisement,delAdvertisement,saveAdvertisement,quitAndUserAd,uploadApk,checkVideo } from '@/services/visitorRecord';

export default{
  namespace: 'visitorRecordModel',
  state: {
    data: [],
  },
  effects: {
    *getVisitorRecord({callback,payload},{ call, put }) {
      const response = yield call(getVisitorRecord,payload);
      yield put({
        type: "getAd",
      });
      if(callback) callback(response);
    },
    *getAdvertisement({callback,payload},{ call, put }) {
      const response = yield call(getAdvertisement,payload);
      yield put({
        type: "getAd",
      });
      if(callback) callback(response);
    },
    *delAdvertisement({callback,payload},{ call, put }) {
      const response = yield call(delAdvertisement,payload);
      yield put({
        type: "del",
      });
      if(callback) callback(response);
    },
    *saveAdvertisement({callback,payload},{ call, put }) {
      const response = yield call(saveAdvertisement,payload);
      yield put({
        type: "save",
      });
      if(callback) callback(response);
    },
    *quitAndUserAd({callback,payload},{ call, put }) {
      const response = yield call(quitAndUserAd,payload);
      yield put({
        type: "quit",
      });
      if(callback) callback(response);
    },
    *uploadApk({callback,payload},{ call, put }) {
      const response = yield call(uploadApk,payload);
      yield put({
        type: "apk",
      });
      if(callback) callback(response);
    },
    *checkVideo({callback,payload},{ call, put }) {
      const response = yield call(checkVideo,payload);
      yield put({
        type: "check",
      });
      if(callback) callback(response);
    },
  },
  reducers: {
    getAd(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    del(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    save(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    quit(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    apk(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
    check(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },
  },
};
