diff --git a/lib/services/analytics-service.ts b/lib/services/analytics-service.ts index 9bd1513..a7374f2 100644 --- a/lib/services/analytics-service.ts +++ b/lib/services/analytics-service.ts @@ -424,6 +424,23 @@ export interface PredictionsOverview { message?: string; } +export interface BatchPredictionsResponse { + success: boolean; + storeId?: string; + historicalPeriod?: number; + horizons?: number[]; + simulationFactors?: number[]; + predictions?: { + [horizon: string]: { + [simulationFactor: string]: PredictionsOverview; + }; + }; + totalEntries?: number; + generatedAt?: string; + message?: string; +} + + // Prediction Service Functions /** @@ -546,3 +563,28 @@ export const getPredictionsOverviewWithStore = async ( const storeId = getStoreIdForUser(); return getPredictionsOverview(daysAhead, period, storeId, simulation); }; + +/** + * Get all cached predictions in one request (for client-side switching) + * @param period Historical period in days (default: 90) + * @param storeId Optional storeId for staff users + */ +export const getBatchPredictions = async ( + period: number = 90, + storeId?: string, +): Promise => { + const params = new URLSearchParams({ + period: period.toString(), + }); + if (storeId) params.append("storeId", storeId); + + const url = `/analytics/predictions/batch?${params.toString()}`; + return clientFetch(url); +}; + +export const getBatchPredictionsWithStore = async ( + period: number = 90, +): Promise => { + const storeId = getStoreIdForUser(); + return getBatchPredictions(period, storeId); +};