import Mock from 'mockjs'

import user from './system/user'
import resource from './system/resource'
import dict from './system/dict'
import dept from './system/dept'
import area from './system/area'
import role from './system/role'
import log from './system/log'
import config from './system/config'
import search from './remote-search'
import common from './sanitation/common'
import staff from './sanitation/staff'
import device from './sanitation/device'
import job from './sanitation/job'

const mocks = [
  ...user,
  ...resource,
  ...dict,
  ...area,
  ...dept,
  ...role,
  ...log,
  ...config,
  ...search,
  ...common,
  ...staff,
  ...device,
  ...job
]

Mock.XHR.prototype.proxy_send = Mock.XHR.prototype.send
Mock.XHR.prototype.send = function() {
  if (this.custom.xhr) {
    this.custom.xhr.withCredentials = this.withCredentials || false
  }
  this.proxy_send(...arguments)
}
Mock.setup({
  timeout: '350-600'
})

for (const i of mocks) {
  console.log(i)
  Mock.mock(new RegExp(i.url), i.type || 'get', i.response)
}

export default Mock
