import { API_URL } from '../../config'
import { fallbackTo, isString } from '../../utils/types'
import { SignUp, SignUpBody, SignUpResponse } from './types'

const composeSignUpURL = () => (
    API_URL + '/signup?'
)

const composeSignUpBody = (formData: FormData): SignUpBody => ({
    email: fallbackTo(formData.get('email'), isString, ''),
    password: fallbackTo(formData.get('password'), isString, ''),
    name: fallbackTo(formData.get('name'), isString, ''),
    surname: fallbackTo(formData.get('surname'), isString, ''),
})

const processSignUp = (data: SignUpResponse): SignUp => {
    if (!data.Success) {
        throw new Error(data.Message)
    }

    return true
}

export { composeSignUpURL, composeSignUpBody, processSignUp }
