import {useMutation} from "react-query";
import auth from "@react-native-firebase/auth";
import {useUpdateUserData} from "@/hooks/firebase/useUpdateUserData";
import {ProfileType} from "@/contexts/AuthContext";

export const useSignUp = () => {
    const {mutateAsync: updateUserData} = useUpdateUserData()

    return useMutation({
        mutationKey: ["signUp"],
        mutationFn: async ({email, password, firstName, lastName}: { email: string, password: string, firstName: string, lastName: string }) => {
            const res = await auth().createUserWithEmailAndPassword(email, password);
            await updateUserData({newUserData: {userType: ProfileType.PARENT, firstName: firstName, lastName: lastName}, customUser: res.user});
        }
    });
}