import { useQuery } from '@tanstack/react-query';
import {
    getLegacyContracts,
    getLegacyContractsItems,
} from '@/lib/dashboard/dashboard-api';

/**
 * Fetch legacy contract list
 */
export const useGetLegacyContractList = (
    customerId: string | number
) => {
    return useQuery({
        queryKey: ['legacy-contract-list', customerId],
        queryFn: async () => {
            const res = await getLegacyContracts();
            return res.data.results;
        },
        enabled: Boolean(customerId),
        staleTime: 1000 * 60 * 5,
    });
};

/**
 * Fetch single legacy contract content
 */
export const useGetLegacyContractItemData = (
    id: number,
    customerId: string | number
) => {
    return useQuery({
        queryKey: ['legacy-contract-item', id, customerId],
        queryFn: async () => {
            const res = await getLegacyContractsItems(id, customerId);
            return res.data.results;
        },
        enabled: Boolean(customerId && id),
        staleTime: 1000 * 60 * 5,
    });
};
