import request from '@/utils/request'

// 登录方法
export function login(username, password, code, uuid, lang) {
  const data = {
    user_code: username,
    password,
    code,
    uuid,
    qcc_language: lang
  }
  return request({
    url: '/app/login/appLogin',
    headers: {
      isToken: false,
      repeatSubmit: false
    },
    method: 'post',
    data: data
  })
}

// 获取用户详细信息
export function getInfo() {
  return request({
    url: '/app/login/getUserInfo',
    method: 'get'
  })
}

// 退出方法
export function logout() {
  return request({
    url: '/app/login/logout',
    method: 'post',
    ignoreError: true
  })
}

// 获取验证码
export function getCodeImg() {
  return request({
    url: '/captchaImage',
    headers: {
      isToken: false
    },
    method: 'get',
    timeout: 20000
  })
}

// 注册方法
export function signUp(username, password, first_name, last_name, country, lang, shareCode, phone, phone_prefix
  , utm_source, utm_medium, utm_content, utm_campaign, utm_blocka) {
  const data = {
    email: username,
    password,
    first_name,
    last_name,
    country,
    language: lang, shareCode,
    phone, phone_prefix,
    utm_source, utm_medium, utm_content, utm_campaign, utm_blocka
  }
  return request({
    url: '/app/register/appRegister',
    headers: {
      isToken: false,
      repeatSubmit: false
    },
    method: 'post',
    data: data
  })
}

// 根据IP获取国家
export function checkCountryByIP() {
  return request({
    url: 'https://ipapi.co/json/',
    headers: {
      isToken: false
    },
    method: 'get',
    ignoreError: true
  })
}

// 发送找回密码验证码
export function sendCodeForgot(data) {
  return request({
    url: '/app/register/sendCode',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data
  })
}

// 校验验证码
export function checkCodeForgot(data) {
  return request({
    url: '/app/register/checkCode',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data
  })
}

// 保存新密码
export function saveNewPwdForgot(data) {
  return request({
    url: '/app/register/saveNewPwd',
    headers: {
      isToken: false
    },
    method: 'post',
    data: data
  })
}