import api, { unwrap } from './request';

export interface ForecastKpiResp extends Record<string, unknown> {
  forecastId: number;
  forecastMonth: string;
  targetOrgId?: number;
  targetOrgName?: string;
  metricCode: string;
  metricName?: string;
  forecastValue?: number;
  lowerBound?: number;
  upperBound?: number;
  method?: string;
  methodName?: string;
  basePeriod?: string;
  sampleCount?: number;
  generatedAt?: string;
}

export interface ForecastKpiSearchParam {
  forecastMonth?: string;
  targetOrgId?: number;
  metricCode?: string;
  pageNum?: number;
  pageSize?: number;
}

export interface ForecastKpiRegenerateReq {
  forecastMonth: string;
  method?: string;
}

export const forecastKpiApi = {
  list: (params?: ForecastKpiSearchParam) =>
    unwrap<{ list: ForecastKpiResp[]; total: number }>(
      api.get('/api/forecast-kpi', { params })
    ),
  regenerate: (req: ForecastKpiRegenerateReq) =>
    unwrap<number>(api.post('/api/forecast-kpi/regenerate', req)),
};
