import type { MockMethod } from 'vite-plugin-mock'

const List = [
  {
    createBy: 'admin',
    createTime: '2024-12-03 02:42:51',
    updateBy: null,
    updateTime: null,
    remark: '管理员',
    userId: 1,
    deptId: 103,
    userName: 'admin',
    nickName: '若依',
    email: 'ry@163.com',
    phonenumber: '15888888888',
    sex: '1',
    avatar: '',
    password: null,
    status: '0',
    delFlag: '0',
    loginIp: '127.0.0.1',
    loginDate: '2024-12-12T06:59:14.000+00:00',
    dept: {
      createBy: null,
      createTime: null,
      updateBy: null,
      updateTime: null,
      remark: null,
      deptId: 103,
      parentId: null,
      ancestors: null,
      deptName: '研发部门',
      orderNum: null,
      leader: '若依',
      phone: null,
      email: null,
      status: null,
      delFlag: null,
      parentName: null,
      children: [],
    },
    roles: [],
    roleIds: null,
    postIds: null,
    roleId: null,
    admin: true,
  },
  {
    createBy: 'admin',
    createTime: '2024-12-03 02:42:51',
    updateBy: null,
    updateTime: null,
    remark: '测试员',
    userId: 2,
    deptId: 105,
    userName: 'ry',
    nickName: '若依',
    email: 'ry@qq.com',
    phonenumber: '15666666666',
    sex: '1',
    avatar: '',
    password: null,
    status: '0',
    delFlag: '0',
    loginIp: '127.0.0.1',
    loginDate: '2024-12-03T02:42:51.000+00:00',
    dept: {
      createBy: null,
      createTime: null,
      updateBy: null,
      updateTime: null,
      remark: null,
      deptId: 105,
      parentId: null,
      ancestors: null,
      deptName: '测试部门',
      orderNum: null,
      leader: '若依',
      phone: null,
      email: null,
      status: null,
      delFlag: null,
      parentName: null,
      children: [],
    },
    roles: [],
    roleIds: null,
    postIds: null,
    roleId: null,
    admin: false,
  },
]

export default [
  {
    url: '/system/user/list',
    method: 'get',
    response({ query }: any) {
      const { username, pageNo = 1, pageSize = 20 } = query
      const mockList = List.filter((item) => !(username && !item.userName.includes(username)))
      const list = mockList.filter((item, index) => index < pageSize * pageNo && index >= pageSize * (pageNo - 1))
      return {
        code: 200,
        msg: 'success',
        // data: { list, total: mockList.length },
        rows: list,
        total: mockList.length,
      }
    },
  },
  {
    url: '/system/user',
    method: 'post',
    response() {
      return {
        code: 200,
        msg: '模拟保存成功',
      }
    },
  },
  {
    url: '/system/user',
    method: 'put',
    response() {
      return {
        code: 200,
        msg: '模拟修改成功',
      }
    },
  },
  {
    url: '/system/user/:userId',
    method: 'delete',
    response() {
      return {
        code: 200,
        msg: '模拟删除成功',
      }
    },
  },
  {
    url: '/system/user/',
    method: 'get',
    response() {
      return {
        msg: '操作成功',
        code: 200,
        roles: [
          {
            createBy: null,
            createTime: '2024-12-03 02:42:52',
            updateBy: null,
            updateTime: null,
            remark: '普通角色',
            roleId: 2,
            roleName: '普通角色',
            roleKey: 'common',
            roleSort: 2,
            dataScope: '2',
            menuCheckStrictly: true,
            deptCheckStrictly: true,
            status: '0',
            delFlag: '0',
            flag: false,
            menuIds: null,
            deptIds: null,
            permissions: null,
            admin: false,
          },
        ],
        posts: [
          {
            createBy: 'admin',
            createTime: '2024-12-03 02:42:52',
            updateBy: null,
            updateTime: null,
            remark: '',
            postId: 1,
            postCode: 'ceo',
            postName: '董事长',
            postSort: 1,
            status: '0',
            flag: false,
          },
          {
            createBy: 'admin',
            createTime: '2024-12-03 02:42:52',
            updateBy: null,
            updateTime: null,
            remark: '',
            postId: 2,
            postCode: 'se',
            postName: '项目经理',
            postSort: 2,
            status: '0',
            flag: false,
          },
          {
            createBy: 'admin',
            createTime: '2024-12-03 02:42:52',
            updateBy: null,
            updateTime: null,
            remark: '',
            postId: 3,
            postCode: 'hr',
            postName: '人力资源',
            postSort: 3,
            status: '0',
            flag: false,
          },
          {
            createBy: 'admin',
            createTime: '2024-12-03 02:42:52',
            updateBy: null,
            updateTime: null,
            remark: '',
            postId: 4,
            postCode: 'user',
            postName: '普通员工',
            postSort: 4,
            status: '0',
            flag: false,
          },
        ],
      }
    },
  },
  {
    url: '/system/user/:userId',
    method: 'get',
    response(res) {
      console.log(res)
      return {
        msg: '操作成功',
        code: 200,
        roles: [
          {
            createBy: null,
            createTime: '2024-12-03 02:42:52',
            updateBy: null,
            updateTime: null,
            remark: '普通角色',
            roleId: 2,
            roleName: '普通角色',
            roleKey: 'common',
            roleSort: 2,
            dataScope: '2',
            menuCheckStrictly: true,
            deptCheckStrictly: true,
            status: '0',
            delFlag: '0',
            flag: false,
            menuIds: null,
            deptIds: null,
            permissions: null,
            admin: false,
          },
        ],
        posts: [
          {
            createBy: 'admin',
            createTime: '2024-12-03 02:42:52',
            updateBy: null,
            updateTime: null,
            remark: '',
            postId: 1,
            postCode: 'ceo',
            postName: '董事长',
            postSort: 1,
            status: '0',
            flag: false,
          },
          {
            createBy: 'admin',
            createTime: '2024-12-03 02:42:52',
            updateBy: null,
            updateTime: null,
            remark: '',
            postId: 2,
            postCode: 'se',
            postName: '项目经理',
            postSort: 2,
            status: '0',
            flag: false,
          },
          {
            createBy: 'admin',
            createTime: '2024-12-03 02:42:52',
            updateBy: null,
            updateTime: null,
            remark: '',
            postId: 3,
            postCode: 'hr',
            postName: '人力资源',
            postSort: 3,
            status: '0',
            flag: false,
          },
          {
            createBy: 'admin',
            createTime: '2024-12-03 02:42:52',
            updateBy: null,
            updateTime: null,
            remark: '',
            postId: 4,
            postCode: 'user',
            postName: '普通员工',
            postSort: 4,
            status: '0',
            flag: false,
          },
        ],
      }
    },
  },
] as MockMethod[]
