import { LOG } from "@logger";
import base64 from "react-native-base64";
import axiosRequest from "../axiosRequest";
import type { IuserInformations } from "./types";

const log = LOG.extend("getUserInformations");

const getUserInformations = async (userAccessToken: string) => {
	log.http("getUserInformations", userAccessToken);
	const basictoken = base64.encode("admin:admin");
	log.http("basictoken", basictoken);

	const response = await axiosRequest<IuserInformations>({
		url: "/user-info/",
		method: "GET",
		headers: {
			// biome-ignore lint/style/useNamingConvention: <Header>
			Authorization: `Basic ${basictoken}`,
		},
	});
	log.http(JSON.stringify(response, null, 2));
	return response;
};

export default getUserInformations;

export const parseUserInformationsErrors = (error: unknown): string => {
	// if (error instanceof AxiosError && error.response) {
	// 	switch (error.response.status) {
	// 		case 401:
	// 			return "Wrong username or password";
	// 		default:
	// 			return "Unknown Error. Please try again.";
	// 	}
	// }
	// if (error instanceof AxiosError && error.request) {
	// 	return "Network error";
	// }
	return "Failure to fetch user informations. Please try again.";
};
