import { languageInstance } from "@shared";
import { User, UserCity } from "../UserStore";

export const getMeApi = async (): Promise<User> => {
  const response = await languageInstance("ru").get("/auth/me");
  return response.data as User;
};

export const getMeCitiesApi = async (): Promise<{
  ru: UserCity[];
  en: UserCity[];
  zh: UserCity[];
}> => {
  const [ru, en, zh] = await Promise.all([
    languageInstance("ru").get("/auth/me"),
    languageInstance("en").get("/auth/me"),
    languageInstance("zh").get("/auth/me"),
  ]);

  return {
    ru: ((ru.data as User).cities ?? []),
    en: ((en.data as User).cities ?? []),
    zh: ((zh.data as User).cities ?? []),
  };
};
