import { cowHttp, frogHttp } from '@/lib/http/instances'
import type {
  LoginRequest,
  LoginResponse,
  User,
  CompleteUserInfoRequest,
  UpdateUserInfoRequest,
  CheckNicknameRequest,
} from './types'

export const authService = {
  // 第三方登录&注册
  login: (data: LoginRequest): Promise<LoginResponse> => {
    return frogHttp.post('/web/third/login', data)
  },

  logout: (): Promise<void> => {
    return frogHttp.post('/web/user/logout')
  },

  getCurrentUser: (): Promise<User> => {
    return frogHttp.post('/web/user/base-info')
  },

  completeUserInfo: (data: CompleteUserInfoRequest): Promise<void> => {
    return frogHttp.post('/web/user/complete-user-info', data)
  },

  updateUserInfo: (data: UpdateUserInfoRequest): Promise<void> => {
    return frogHttp.post('/web/user/edit-user-info', data)
  },

  deleteUser: (): Promise<void> => {
    return frogHttp.post('/web/user/del')
  },

  checkNickname: (data: CheckNicknameRequest): Promise<boolean> => {
    return frogHttp.post('/web/user/nickname-check', data, { ignoreError: true })
  },

  checkText: (data: { content: string }): Promise<string> => {
    return cowHttp.post('/web/content/check', data, { ignoreError: true })
  },
}
