import { computeDateRange } from './dateRange.uts' import { rpcOrEmptyArray, rpcOrNull } from './rpc.uts' export type CouponAnalysisData = { overviewRow: UTSJSONObject | null typeList: Array channelList: Array trendList: Array conversionList: Array } export async function fetchCouponAnalysis(period: string): Promise { const { startIso, endIso } = computeDateRange(period) const overviewRow = await rpcOrNull('rpc_coupon_effectiveness_overview', { p_start: startIso, p_end: endIso } as UTSJSONObject) const typeList = await rpcOrEmptyArray('rpc_coupon_type_stats', { p_start: startIso, p_end: endIso } as UTSJSONObject) const channelList = await rpcOrEmptyArray('rpc_coupon_channel_stats', { p_start: startIso, p_end: endIso } as UTSJSONObject) const trendList = await rpcOrEmptyArray('rpc_coupon_trend_daily', { p_start: startIso, p_end: endIso } as UTSJSONObject) const conversionList = await rpcOrEmptyArray('rpc_coupon_conversion_effect', { p_start: startIso, p_end: endIso } as UTSJSONObject) return { overviewRow, typeList, channelList, trendList, conversionList } }