// imports

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

// types

export type GetTicketResponse = Ticket;

const useGetTicket = (id: ComputedRef<number | string>) => {
    // state

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

    // methods

    const handleGetTicket = async (id: string | number | undefined) => {
        const { data } = await axios.get<GetTicketResponse>(
            `${API_ENDPOINTS.tickets.get_one}/${id}`
        );
        return data;
    };

    return useQuery({
        queryKey: [QUERY_KEYS.ticket, id],
        queryFn: () => handleGetTicket(id.value),
    });
};

export default useGetTicket;
