/*
 * @Author: your name
 * @Date: 2021-11-11 10:35:56
 * @LastEditTime: 2023-09-27 15:00:37
 * @LastEditors: code4eat awesomedema@gmail.com
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: /KC-MiddlePlatform/service/login.ts
 */

import { request } from 'umi';

export const getHospConfigBySign = async (hospSign: string) => {
  return request<
    {
      loginTips: any;
      loginPic: any;
      loadType: number;
      hospAbbreviation: any;
      hospSign: string;
      id: string;
      name: string;
      systemName: string;
    }[]
  >('/centerSys/hospital/getHospConfigBySign', {
    method: 'GET',
    params: { hospSign },
  });
};

//获取上次登陆的系统

export const getLastLoginSys = async (params: { hospId: string; userId: number }) => {
  return request('/centerSys/parameter/getLastSystem', {
    method: 'GET',
    params,
  });
};

//获取登陆密码为默认密码时的判断类型

export const getLoginTipType = async () => {
  return request('/centerSys/parameter/getList?pageSize=500&current=1', {
    method: 'GET',
  });
};

//获取该账户拥有的子应用列表
export const getHospSubSystemList = async () => {
  // return request<userRelationInfo.OwnAppsItem[]>('/centerSys/user/getSystemList', {
  //   method: 'GET',
  // });
};

export type UserDataType = {
  name: string;
  token: string;
  userId: number;
  youshuToken: string; //用于有数链接展示
};

export const login = async (data: LoginApi.LoginParams) => {
  return request<UserDataType>('/oauth2/login', {
    method: 'POST',
    data: data,
  });
};

export const logout = async () => {
  return request('/oauth2/logout', {
    method: 'POST',
  });
};

//获取qiankun 子应用列表
export const getQiankunMicroApps = async () => {
  return request('/centerSys/route/list?current=1&pageSize=500', {
    method: 'GET',
  });
};

//新增qiankun 子应用列表
export const addQiankunMicroApps = async (data: { name: string; entry: string }) => {
  return request('/centerSys/route/save', {
    method: 'POST',
    data,
  });
};
