import {UserType} from "@/lib/backend/appwrite_types";
import {redirect} from "next/navigation";
import {ADMIN_DASHBOARD_URL, CLIENTS_DASHBOARD_URL, LOGIN_URL} from "@/lib/constants";
import {useAuth} from "@/lib/hooks/useAuth";

export async function useIsPatient() {
    /**
     * Hook to redirect admin and clients trying to enter patient urls
     * */
    const {userProfile} = await useAuth();
    if (userProfile) {
        switch (userProfile.userType) {
            case UserType.ADMIN:
                redirect(ADMIN_DASHBOARD_URL)
                return;
            case UserType.PATIENT:
                return;
            default:
                redirect(CLIENTS_DASHBOARD_URL)
        }
    } else {
        redirect(LOGIN_URL)
    }
}