import Mock from 'mockjs';
import type { GetParams } from '@/types/global';
import { parseUrlQuery } from '@/utils/parse-url-query';
import setupMock, { successResponseWrap } from '@/mocks/setup';

const { Random } = Mock;

const data = Mock.mock({
  'list|55': [
    {
      'id|8': /[A-Z][a-z][-][0-9]/,
      'number|2-3': /[0-9]/,
      'name|4-8': /[A-Z]/,
      'contentType|1': ['img', 'horizontalVideo', 'verticalVideo'],
      'count|2-3': /[0-9]/,
      'status|1': ['online', 'offline'],
      'filterType|1': ['artificial', 'rules'],
      createdTime: Random.datetime(),
    },
  ],
});

setupMock({
  setup() {
    Mock.mock(/\/api\/list\/policy/, (params: GetParams) => {
      const { current = '1', pageSize = '10' } = parseUrlQuery(params.url);
      const p = Number(current);
      const ps = Number(pageSize);
      return successResponseWrap({
        list: data.list.slice((p - 1) * ps, p * ps),
        total: 55,
      });
    });
  },
});
