/**
 * @flow
 */
import { RandomNumBoth } from '../Tool';
import localData from './localData';


// 获取用户保单列表
function get001001(data) {
  const { policy } = localData;
  const param = JSON.parse(data);
  const result = [];
  console.log('policy:',policy)
  console.log('data:',param)
  policy.forEach((item) => {
    if (item.uid === param.uid) {
      result.push(item);
    }
  });
  return result;
}

//获取保险产品
function get001002() {
  const { product } = localData;
  return product;
}


const mockMap = {
  '001001': get001001,
  '001002': get001002,
};


export default function getMockData(url, config, callback) {
  console.log('getMockData:', url, config);
  const time = RandomNumBoth(1, 3);
  // 随机暂停  1 - 3秒
  console.log('模拟请求：', time, '秒');
  setTimeout(
    () => {
      const result = mockMap[config.APICode](config.data)
      console.log('result:',result)
      callback(result);
    },
    time * 1000,
  );
}
