// imports

import { useQuery } from "@tanstack/vue-query";
import { useAppParams } from "~/composables/global/useAppParams";
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";

// types

export type GetAllNotificationsResponse = ApiPaginated<Notification>;

const useGetAllNotifications = () => {
    // state

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

    const { sort, status, page } = useAppParams();

    // methods

    const handleGetAllNotifications = async () => {
        const { data } = await axios.get<GetAllNotificationsResponse>(API_ENDPOINTS.account.notifications.get_all, {
            params: {
                sort: sort.value ?? "created_at",
                filter: status.value,
                offset: Number(page.value) * 10 - 10,
                limit: 10,
            },
        });
        return data;
    };

    return useQuery({
        queryKey: [QUERY_KEYS.notifications, sort, status, page],
        queryFn: () => handleGetAllNotifications(),
    });
};

export default useGetAllNotifications;
