import type { AxiosResponse } from 'axios';
import { default as Axios } from 'axios'
// import { IPayload } from 'model'
import { GlobalConfig, PayloadMessageTypes } from '../common'

import { tools } from '@tools'

import { helpers } from '@vuelidate/validators'
const { withAsync } = helpers

// const SITE_URL = GlobalConfig.uri.site
const VALIDATE_USER_URL = import.meta.env.VITE_MONGODB_HOST + '/users/'

export const registereduser = withAsync(_registereduser)

export function _registereduser(userName: string) {

  const onSuccess = (res: AxiosResponse) => {
    return res.status !== PayloadMessageTypes.statusfound
  }

  return Axios.get(VALIDATE_USER_URL + tools.getEnv('VITE_APP_ID') + '/' + tools.rimuoviAtInizio(userName))
    .then(onSuccess)
    .catch((err) => {
      return true
    })

}
