/*
 * @Page: 文件描述
 * @Author: Fengyu
 * @Date: 2025-12-11 16:03:49
 * @LastEditors: Fengyu
 * @LastEditTime: 2025-12-12 14:00:41
 */
/*
 * @Author: wyd
 * @Date: 2024-02
 * @LastEditors: wyd
 * @LastEditTime: 2024-07
 * @Description: 登录api
 */
import { http } from '@/utils/http'
import type { loginItem, captchaItem, captchaResult, smsItem, registerItem, forgetItem, loginResult, useInfoResult } from '@/types/login'

/**
 * @description: 登录
 * @param {*} data isBind 1微信未绑定系统用户 0已绑定
 * @return {*}
 */
export const loginApi = (data: loginItem, isBind: number) => {
  if (isBind === 1) {
    // 微信登录且需要绑定
    return http<loginResult>({
      method: 'POST',
      url: '/xcxBind',
      data
    })
  }
  if (data.type === 1) {
    // 短信登录
    return http<loginResult>({
      method: 'POST',
      url: '/smsLogin',
      data
    })
  }
  // 账号密码登录
  return http<loginResult>({
    method: 'POST',
    url: '/mpLogin',
    data
  })
}

/**
 * @description: 获取用户信息
 * @param {*} data
 * @return {*}
 */
export const getUserInfoApi = () => {
  return http<useInfoResult>({
    method: 'GET',
    url: '/getInfo'
  })
}

/**
 * @description: 获取验证码图片
 * @param {*} data
 * @return {*}
 */
export const getCaptchaImageApi = (data?: captchaItem) => {
  return http<captchaResult>({
    method: 'GET',
    url: '/captchaImage',
    data
  })
}

/**
 * @description: 获取短信验证码
 * @param {*} data
 * @return {*}
 */
export const getSmsApi = (data?: smsItem) => {
  return http({
    method: 'GET',
    url: '/captchaSms',
    data
  })
}

/**
 * @description: 注册
 * @param {*} data
 * @return {*}
 */
export const registerApi = (data?: registerItem) => {
  return http({
    method: 'POST',
    url: '/register',
    data
  })
}

/**
 * @description: 忘记密码
 * @param {*} data
 * @return {*}
 */
export const forgetApi = (data?: forgetItem) => {
  return http({
    method: 'POST',
    url: '/password/reset',
    data
  })
}

/**
 * @description: 微信登录
 * @param {*} data
 * @return {*}
 */
export const weixinApi = (data: { code: string }) => {
  return http<loginResult>({
    method: 'POST',
    url: '/xcxLogin',
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    data
  })
}

/**
 * @description: 退出登录
 * @param {*}
 * @return {*}
 */
export const quiteApi = () => {
  return http({
    method: 'POST',
    url: '/logout'
  })
}

/**
 * @description: 手机号登录
 * @param {*} data
 * @return {*}
 */
export const phoneLoginApi = (data: { code: string }) => {
  return http<loginResult>({
    method: 'POST',
    url: '/xcxPhoneLogin',
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    data
  })
}

// 手机号登录
export const h5PhoneLoginApi = (phone: string) => {
  return http({
    method: 'POST',
    url: `/h5PhoneLogin?phone=${phone}`
  })
}
