import { CreateTosFormValues } from "@/components/forms/tos/create/CreateTosForm";
import {createTos, deleteTos, getAllTos, getTosByVersion, toggleTosActive} from "@/service/apis/tos";
import { ServerResponse } from "@/types";
import {useMutation, useQuery} from "@tanstack/react-query";
export type TOS = {
  isActive: boolean;
  id: string;
  title: string;
  content: string;
  version: string;
  createdAt: Date;
  updatedAt: Date;
};

export type GetAllTosResponse = {
  status: number;
  data: TOS[];
  message: string;
};
export const useGetAllTos = () =>
  useQuery<GetAllTosResponse>({
    queryKey: ["get-all-tos"],
    queryFn: getAllTos,
    retry: false,
    refetchOnWindowFocus: false,
  });

export const useCreateTos = () => useMutation<ServerResponse, Error, CreateTosFormValues, ServerResponse>({mutationFn: createTos});
export const useGetSingleTos = () => useMutation({mutationFn:getTosByVersion})
export const useTosToggleActive = () => useMutation({mutationFn:toggleTosActive})
export const useDeleteTos = () => useMutation({mutationFn:deleteTos})