export async function getDailyLimit(token: string) {
    try {
        const response = await fetch("/api/customer/daily-limit", {
            method: "GET",
            headers: {
                "Authorization": `Bearer ${token}`,
                "X-Login-Type": "IB",
            },
        });

        if (response.status === 400) {
            const errorData = await response.json();
            if (errorData?.error === "NO DAILY LIMIT SET FOR USER") {
                return null;
            } else {
                throw new Error(errorData?.error || "Bad Request");
            }
        }

        if (!response.ok) {
            throw new Error(`Failed to fetch daily limit: ${response.status}`);
        }

        const data = await response.json();
        return data;
    } catch (error) {
        console.error("Error fetching daily limit:", error);
        throw error;
    }
}
