import { apiFetch } from './client';

export type FastingOverview = {
  enabled: boolean;
  lastMealAt: string | null;
  goalHours: number;
  goalOptions: number[];
  warningHours: number;
  cautionHours: number;
  windowStartHour: number;
  previousFastOutcome: { success: boolean; missedMs: number | null };
};

export function fetchFastingOverview() {
  return apiFetch<{ overview: FastingOverview }>('/tracking/fasting');
}

export function setFastingEnabled(enabled: boolean) {
  return apiFetch<{ overview: FastingOverview }>('/tracking/fasting/enable', {
    method: 'POST',
    body: { enabled },
  });
}

export function setFastingGoal(goalHours: number) {
  return apiFetch<{ overview: FastingOverview }>('/tracking/fasting/goal', {
    method: 'POST',
    body: { goalHours },
  });
}

export function setFastingWindowStart(windowStartHour: number) {
  return apiFetch<{ overview: FastingOverview }>('/tracking/fasting/window-start', {
    method: 'POST',
    body: { windowStartHour },
  });
}
