/*
 * @Author: your name
 * @Date: 2021-11-11 11:46:42
 * @LastEditTime: 2022-01-10 15:05:16
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /KC-MiddlePlatform/mock/login.ts
 */

import { Request, Response } from 'express';

const getList = (req: Request, res: Response, u: string) => {
  const dataSource = [
    {
      name: '医院一',
      value: 1,
    },
    {
      name: '医院二',
      value: 2,
    },
    {
      name: '医院三',
      value: 3,
    },
  ];
  const result = {
    data: {
      list: dataSource,
      totalCount: dataSource.length,
      current: 1,
    },
    success: true,
    status: 200,
  };

  return res.json(result);
};

const postData = (req: Request, res: Response, u: string) => {
  const { account, password } = req.body;
  if (account == 'admin' && password == '123') {
    const result = {
      data: {
        name: '管理员',
        token:
          'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjEwMjgxNTIyOTc4LCJ1c2VySWQiOjMwNTd9.kr_TcZrhARPrCXzE5nhWd7V9B4rULRrFrLgMeEmTcR0',
        userId: 3057,
      },
      success: true,
      status: 200,
    };

    setTimeout(() => {
      return res.json(result);
    }, 2000);
  } else {
    const result = {
      data: {
        a: 1,
      },
      success: false,
      errorMessage: '用户名或密码错误！',
      status: 200,
    };
    return res.json(result);
  }
};

const getHospSubSystemList = (req: Request, res: Response) => {
  const result = {
    data: [
      {
        icon: 'https://i.postimg.cc/J4fsWx1V/2x.png',
        id: 0,
        name: '平台管理',
        url: '/platform/index',
      },
      {
        icon: 'https://i.postimg.cc/yNrSZ4pN/2x.png',
        id: 1,
        name: '智慧查检系统',
        url: '/app1',
      },
    ],
    success: true,
    status: 200,
  };

  return res.json(result);
};

export default {
  'GET /api/getSubHosp': getList,
  'POST /api/login': postData,
  'GET /api/getHospSubSystemList': getHospSubSystemList,
};
