/**
 * @desc 检查用户名是否存在,true存在,false不存在
 */
import { defaultSuccess, defaultError, http } from '@/plugins/axios'
import type { AxiosResponse } from 'axios'
export interface Params {
	/** name */
	name: string
}

export default async function (
	params: Params,
	success: (data: boolean) => void = defaultSuccess,
	fail: (error: { code: string; error?: string }) => void = defaultError,
): Promise<void> {
	return http({
		method: 'get',
		url: `/user/exist-name`,

		params,
	})
		.then((data: AxiosResponse<boolean, unknown>) => {
			success(data.data)
		})
		.catch((error: { code: string; error?: string }) => fail(error))
}
