import { request } from 'umi';
import { erpApi } from './api'
export interface LoginParamsType {
  username: string;
  password: string;
  uuid: string,
  code: string,
  platformType: string
}

// export async function fakeAccountLogin(params: LoginParamsType) {
//   return request<API.LoginStateType>('/api/login/account', {
//     method: 'POST',
//     data: params,
//   });
// }
export async function fakeAccountLogin(params: any) {
  return request(erpApi + '/erp/user/login', {
    method: 'POST',
    data: params,
  });
}

export async function getFakeCaptcha(mobile: string) {
  return request(`/api/login/captcha?mobile=${mobile}`);
}

export async function outLogin() {
  return request(erpApi + '/erp/user/logout', {
    method: 'DELETE'
  });
}
// export async function getCode() {
//   return request(api + '/code');
// }
/**查询版本号 */
export async function getVersions() {
  return request(erpApi + '/erp/config/sysVersion/versions')
}
/**查询私人定制用户 */
export async function getPrivate() {
  return request(erpApi + '/erp/config/sysVersion/private')
}
/**获取钉钉扫码前的后台KEY*/
export async function getDingKey() {
  return request(erpApi + '/erp/user/dLoginState')
}
/**钉钉登录*/
export async function ddlogin(params: { code: string, stateKey: string, state: string }) {
  let { code, stateKey, state } = params
  return request(erpApi + `/erp/user/dLogin?code=${code}&stateKey=${stateKey}&state=${state}`, {
    method: 'POST'
  })
}
// 选择公司
export async function selectCompanyApi(companyId: number) {
  return request(erpApi + `/erp/user/chooseCompany/${companyId}`, {
    method: 'PUT'
  });
}
// 手机钉钉验证码获取
export async function getCode(phone: string) {
  return request(erpApi + `/erp/user/dCodeLoginState/${phone}`)
}
// 手机短信验证码获取
export async function getNoteCode(phone: string) {
  return request(erpApi + `/erp/user/smsCodeLoginState/${phone}`)
}
// 手机登录
export async function phoneLogin(params: { phone: string, code: string }) {
  return request(erpApi + `/erp/user/dCodeLogin`, {
    method: 'POST',
    data: params
  })
}
// 查询是否在更新
export async function isPreserve() {
  return request(erpApi + '/erp/config/sysVersion/preserve')
}