import {getDetailUnitList,getDetailCommunityList,deleteUnit,getOwnerQr,updateOwner,saveOwner,getOwnerDetail,getOwner, getTosUser,delAdvertisement,saveAdvertisement,quitAndUserAd,uploadApk,checkVideo } from '@/services/tosUser';

export default{
  namespace: 'tUModel',
  state: {
    data: [],
  },
  effects: {
    *getTosUser({callback,payload},{ call, put }) {
      const response = yield call(getTosUser,payload);
      yield put({
        type: "get",
      });
      if(callback) callback(response);
    },

    *getOwner({callback,payload},{ call, put }) {
      const response = yield call(getOwner,payload);
      yield put({
        type: "get",
      });
      if(callback) callback(response);
    },
    *getOwnerDetail({callback,payload},{ call, put }) {
      const response = yield call(getOwnerDetail,payload);
      yield put({
        type: "get",
      });
      if(callback) callback(response);
    },
    *saveOwner({ callback, payload }, { call, put }) {
      const response = yield call(saveOwner,payload);
      yield put({
        type: "save",
      });
      if(callback) callback(response);
    },
    *updateOwner({callback,payload},{ call, put }) {
      const response = yield call(updateOwner,payload);
      yield put({
        type: "save",
      });
      if(callback) callback(response);
    },
    *getOwnerQr({callback,payload},{ call, put }) {
      const response = yield call(getOwnerQr,payload);
      yield put({
        type: "save",
      });
      if(callback) callback(response);
    },

    *getDetailCommunityList({callback,payload},{ call, put }) {
      const response = yield call(getDetailCommunityList,payload);
      yield put({
        type: "save",
      });
      if(callback) callback(response);
    },
    *getDetailUnitList({callback,payload},{ call, put }) {
      const response = yield call(getDetailUnitList,payload);
      yield put({
        type: "save",
      });
      if(callback) callback(response);
    },


    *deleteUnit({callback,payload},{ call, put }) {
      const response = yield call(deleteUnit,payload);
      yield put({
        type: "del",
      });
      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: {
    get(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },

   /* getOwner(state, action) {
      return {
        ...state,
        data:action.payload || {},
      };
    },

    getOwnerDetail(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 || {},
      };
    },
  },
};
