import {useAuthContext} from "@/contexts/AuthContext";
import {useMutation, useQueryClient} from "react-query";
import firestore from "@react-native-firebase/firestore";
import {EventData} from "@/hooks/firebase/types/eventData";

export const useUpdateEvent = () => {
    const {user: currentUser} = useAuthContext()
    const queryClients = useQueryClient()

    return useMutation({
        mutationKey: ["updateEvent"],
        mutationFn: async (eventData: Partial<EventData>) => {
            try {
                await firestore()
                    .collection("Events")
                    .doc(eventData.id)
                    .update(eventData);
            } catch (e) {
                console.error(e)
            }
        },
        onSuccess: () => {
            queryClients.invalidateQueries("events")
        }
    })
}