// imports

import { useMutation } from "@tanstack/vue-query";
import { API_ENDPOINTS } from "~/constants";

// types

export type SignInRequest = {
    otp: string;
    phone: string;
};

export type SignInResponse = {
    access: string;
    refresh: string;
};

const useSignIn = () => {
    // state

    const { $axios: axios } = useNuxtApp();

    // methods

    const handleSignIn = async (variables: SignInRequest) => {
        const { data } = await axios.post<SignInResponse>(
            `${API_ENDPOINTS.auth.signin}`,
            variables
        );
        return data;
    };

    return useMutation({
        mutationFn: (variables: SignInRequest) => handleSignIn(variables),
    });
};

export default useSignIn;
