import DeviceInfo from 'react-native-device-info';
import post from '../utils/post';
import request from '../utils/request';
import config from '../utils/config';


export async function login(payload) {
  const data = {};
  data.type = payload.type;
  if (data.type === 'userName') {
    data.data = payload.userName;
  }
  if (payload.authType === 'password') {
    data.authRequest = {
      type: payload.authType,
      parameters: {
        cipher: payload.password,
      },
    };
  }
  console.log(DeviceInfo.getUniqueID());
  data.tokenInfo = {
    productId: config.productId,
    deviceId: `${DeviceInfo.getUniqueID()}`,
  };

  return post(`${config.apiContextPath}/api/auth/login`, data, {}, {}, false);
}

export async function userInfo() {
  return request(`${config.apiContextPath}/api/user/info`);
}
export async function logout() {
  return post(`${config.apiContextPath}/api/auth/logout`);
}
