import {LoginFormValues} from "@/components/forms/login/LoginForm";
import { deleteFile } from "@/service/apis";
import {userLogin} from "@/service/apis/users";
import privateApi from "@/service/http/privateCall.axios";
import {ServerResponse} from "@/types";
import {useMutation, useQuery} from "@tanstack/react-query";
export interface Translation {
  displayName: string;
}
export interface MeData {
  id: string;
  email: string;
  username: string;
  role: "admin" | "developer" | "coordinator" | "doctor";
  send_notif_with_email: boolean;
  translations: Translation[];
}
export interface MeResponse {
  status: number;
  message: string;
  data: MeData;
}

export const useMe = () =>
  useQuery<MeResponse>({
    queryKey: ["me"],
    queryFn: async () => {
      const {data} = await privateApi.get<MeResponse>("/auth/get/me");
      return data;
    },
    staleTime: 1000 * 60 * 5,
    refetchOnMount: false,
    refetchOnWindowFocus: false,
    retry: false,
  });

export const useUserLogin = () =>
  useMutation<ServerResponse, Error, LoginFormValues, ServerResponse>({
    mutationFn: userLogin,
  });


export const useDeleteFile = () => useMutation({mutationFn:deleteFile})