import { apiClient } from './api-client';
import type { z } from 'zod/v4';
import type {
  NutritionTargetResponseSchema,
  SetNutritionTargetInput,
} from '@meshitrack/shared';

export type NutritionTargetResponse = z.infer<typeof NutritionTargetResponseSchema>;

export async function getActiveNutritionTarget(
  householdId: string
): Promise<NutritionTargetResponse | { message: string }> {
  return apiClient.get<NutritionTargetResponse | { message: string }>(
    `/households/${householdId}/nutrition-targets`
  );
}

export async function getNutritionTargetHistory(
  householdId: string
): Promise<NutritionTargetResponse[]> {
  return apiClient.get<NutritionTargetResponse[]>(
    `/households/${householdId}/nutrition-targets/history`
  );
}

export async function setNutritionTarget(
  householdId: string,
  data: SetNutritionTargetInput
): Promise<NutritionTargetResponse> {
  return apiClient.post<NutritionTargetResponse>(
    `/households/${householdId}/nutrition-targets`,
    data
  );
}

export async function calculateTargetPreset(
  householdId: string,
  calories: number,
  strategy: 'maintenance' | 'loss' | 'gain'
): Promise<SetNutritionTargetInput> {
  return apiClient.post<SetNutritionTargetInput>(
    `/households/${householdId}/nutrition-targets/presets`,
    { calories, strategy }
  );
}
