import { useMutation, useQuery } from "@tanstack/react-query";
import * as api from "../service/SupportService";
import { CreatePlanType } from "../types/SupportTypes";

export const useCreateSupport = () => {
  return useMutation({
    mutationFn: (variables: CreatePlanType) => api.createPlan(variables),
  });
};

export const useUpdateSupport = () => {
  return useMutation({
    mutationFn: ({ id, data }: { id: string; data: CreatePlanType }) =>
      api.updatePlan(id, data),
  });
};

export const useGetPlans = () => {
  return useQuery({
    queryKey: ["plans"],
    queryFn: () => api.getPlans(),
  });
};

export const useGetPlanById = (id: string) => {
  return useQuery({
    queryKey: ["plan", id],
    queryFn: () => api.getPlanById(id),
  });
};

export const useDeletePlan = () => {
  return useMutation({
    mutationFn: (id: string) => api.deletePlan(id),
  });
};

export const useGetPlanUsers = (id?: string) => {
  return useQuery({
    queryKey: ["plan-users", id],
    queryFn: () => api.getPlanUsers(id),
    enabled: !!id,
  });
};
