// 根据角色动态生成路由
import { defineFakeRoute } from 'vite-plugin-fake-server/client';
import { faker } from '@faker-js/faker';

export default defineFakeRoute([
    {
        url: '/table/list',
        method: 'post',
        response: ({ body }) => {
            const list = [];
            for (let i = 0; i < body.psgeSize; i++) {
                list.push({
                    id: faker.string.uuid(),
                    avatar: faker.image.avatar(),
                    birthday: faker.date.birthdate(),
                    email: faker.internet.email(),
                    firstName: faker.person.firstName(),
                    lastName: faker.person.lastName(),
                    sex: faker.person.sexType(),
                });
            }
            return {
                success: true,
                code: 200,
                data: {
                    list,
                    total: 77,
                    pageSize: body.pageSize,
                    pageNumber: body.pageNumber,
                },
            };
        },
    },
    {
        url: '/table/add',
        method: 'post',
        response: ({ body }) => {
            if (body.firstName) {
                return {
                    success: true,
                    code: 200,
                    data: {
                        id: faker.string.uuid(),
                    },
                };
            } else {
                return {
                    success: false,
                    code: 400,
                    data: null,
                };
            }
        },
    },
    {
        url: '/table/delete',
        method: 'post',
        response: ({ body }) => {
            if (body.id) {
                return {
                    success: true,
                    code: 200,
                    data: {
                        id: body.id,
                    },
                };
            } else {
                return {
                    success: false,
                    code: 400,
                    data: null,
                };
            }
        },
    },
]);
