import request from '../utils/request';
import { Result } from './types';

// 登录
export interface LoginParams {
  username: string;
  password: string;
  remember: boolean;
  uuid: string;
  code: string;
}

interface LoginDataResult {
  access_token: string;
  expires_in: number;
  pwdmodify_day: number;
  [name: string]: any;
}
export async function loginApi(data: LoginParams) {
  return request<Result<LoginDataResult>>({
    url: '/login',
    method: 'POST',
    data,
  });
}

// 获取验证码
interface CodeResult extends Result {
  img: string;
  captchaEnabled: boolean;
  uuid: string;
}
export async function getCodeApi() {
  return request<CodeResult>({
    url: '/code',
    method: 'GET',
  });
}

// 获取用户信息
interface MedicalDataResult {
  userName: string;
  orgName: string;
  deptName: string;
}
export async function getMedicalInfoApi(data: FormData) {
  const { data: resData } = await request<Result<MedicalDataResult>>({
    url: '/getMedicalInfo',
    method: 'POST',
    data,
  });
  return resData;
}
