import { request } from '@/utils/http'
import type { CaptchaDTO, ConfigDTO, CurrentLoginUserDTO, TokenDTO } from './types'

export interface LoginCommand {
  username: string
  password: string
  captchaCode?: string
  captchaCodeKey?: string
}

export interface RegisterCommand extends LoginCommand {
  nickname?: string
  confirmPassword: string
  email?: string
  phoneNumber?: string
}

export function getConfigApi() {
  return request<ConfigDTO>({ method: 'GET', url: '/app/getConfig' })
}

export function getCaptchaApi() {
  return request<CaptchaDTO>({ method: 'GET', url: '/app/captchaImage', showLoading: false })
}

export function loginApi(data: LoginCommand) {
  return request<TokenDTO>({ method: 'POST', url: '/app/login', data })
}

export function registerApi(data: RegisterCommand) {
  return request<TokenDTO>({ method: 'POST', url: '/app/register', data })
}

export function getLoginUserInfoApi() {
  return request<CurrentLoginUserDTO>({ method: 'GET', url: '/app/getLoginUserInfo' })
}

export function logoutApi() {
  return request<void>({ method: 'POST', url: '/logout', showLoading: false })
}

