import { routerRedux } from 'dva/router';
import * as formService from '../../services/PF/form';

export default {

  namespace: 'PFForm',
  state: {
  },

  subscriptions: {
    setup({ dispatch, history }) {  // eslint-disable-line

    },
  },

  effects: {
    *getSqlsByFormId ({ payload,onComplete }, { call, put }) {
      const ret = yield call(formService.getSqlsByFormId, payload);
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
    *getSqlsByEntityName ({ payload,onComplete }, { call, put }) {
      const ret = yield call(formService.getSqlsByEntityName, payload);
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
    *initOrgBySrcOrg ({ payload,onComplete }, { call, put }) {
      const ret = yield call(formService.initOrgBySrcOrg, payload);
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
    *excuteSqlAndGetResult ({ payload,onComplete }, { call, put }) {
      const ret = yield call(formService.excuteSqlAndGetResult, payload);
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
    *sendInfoToClient ({ payload,onComplete }, { call, put }) {
      const ret = yield call(formService.sendInfoToClient, payload);
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },

    *initFormConfigByName ({ payload,onComplete }, { call, put }) {
      const ret = yield call(formService.initFormConfigByName, payload);
      if (typeof onComplete === 'function') {
        onComplete(ret)
      }
    },
  },

  reducers: {
    save(state, action) {
      return { ...state, ...action.payload };
    },
  },

};
