import { API_ENDPOINTS, requestGet, requestPost } from './index.js';

export const getEmailAvailability = (email) =>
    requestGet(`${API_ENDPOINTS.VALIDATE_SIGNUP_EMAIL}/${encodeURI(email)}`);

export const getNomAvailaibility = (nomDeBid) =>
    requestGet(`${API_ENDPOINTS.VALIDATE_SIGNUP_NOM}/${encodeURI(nomDeBid)}`);

export const loginUser = (username, password) =>
    requestPost({
        path: API_ENDPOINTS.LOGIN,
        body: { username, password },
    });

export const registerNewUser = (user) =>
    requestPost({
        path: API_ENDPOINTS.USER_SIGNUP,
        body: { user },
    });

export const setNomDeBid = (id, auth) => (nomDeBid) =>
    requestPost({
        path: `${API_ENDPOINTS.SET_NOM}/${id}`,
        body: { nomDeBid },
        requestOptions: { Authorization: auth ? `Bearer ${auth}` : null },
    });
