import Mock from 'mockjs';
import type { PostData } from '@/types/global';
import setupMock, { successResponseWrap } from '@/mocks/setup';

setupMock({
  setup() {
    Mock.mock(/\/api\/data-chain-growth/, (params: PostData) => {
      const { quota } = JSON.parse(params.body);
      const getLineData = () => {
        return {
          xAxis: new Array(12).fill(0).map((_item, index) => `${index + 1}\u65e5`),
          data: {
            name: quota,
            value: new Array(12)
              .fill(0)
              .map(() => Mock.Random.natural(1000, 3000)),
          },
        };
      };
      return successResponseWrap({
        count: Mock.Random.natural(1000, 3000),
        growth: Mock.Random.float(20, 100, 2, 2),
        chartData: getLineData(),
      });
    });

    Mock.mock(/\/api\/data-overview/, () => {
      const generateLineData = (name: string) => {
        return {
          name,
          count: Mock.Random.natural(20, 2000),
          value: new Array(8).fill(0).map(() => Mock.Random.natural(800, 4000)),
        };
      };
      const xAxis = new Array(8).fill(0).map((_item, index) => `12.1${index}`);
      return successResponseWrap({
        xAxis,
        data: [
          generateLineData('\u5185\u5bb9\u751f\u4ea7\u91cf'),
          generateLineData('\u5185\u5bb9\u70b9\u51fb\u91cf'),
          generateLineData('\u5185\u5bb9\u66dd\u5149\u91cf'),
          generateLineData('\u6d3b\u8dc3\u7528\u6237\u6570'),
        ],
      });
    });
  },
});
