import apiClient from './client';
import type {
  RegimeMonitor,
  RegimeConfig,
  RegimeFundamentals,
  EventStudyReport,
  RegimeHistoryPoint,
} from '../lib/types';

export function getRegimeMonitor() {
  return apiClient.get<RegimeMonitor>('regime/monitor').then((r) => r.data);
}

export function getRegimeHistory(days = 400) {
  return apiClient
    .get<RegimeHistoryPoint[]>('regime/history', { params: { days } })
    .then((r) => r.data);
}

export function getEventStudy() {
  return apiClient.get<EventStudyReport | null>('regime/event-study').then((r) => r.data);
}

export function getRegimeConfig() {
  return apiClient.get<RegimeConfig>('regime/config').then((r) => r.data);
}

export function updateRegimeConfig(updates: Partial<RegimeConfig>) {
  return apiClient.put<RegimeConfig>('regime/config', updates).then((r) => r.data);
}

export function getRegimeFundamentals() {
  return apiClient.get<RegimeFundamentals>('regime/fundamentals').then((r) => r.data);
}

export function updateRegimeFundamentals(body: {
  f1_score?: number;
  f3_score?: number;
  locked?: boolean;
}) {
  return apiClient.put<RegimeFundamentals>('regime/fundamentals', body).then((r) => r.data);
}

export function refreshRegimeFundamentals() {
  return apiClient
    .post<RegimeFundamentals>('regime/fundamentals/refresh')
    .then((r) => r.data);
}
