import { apiClient } from './client';
import type {
  SimulationTemplate,
  SimulationTemplateCreateInput,
  SimulationTemplatePatchInput,
} from './types';

export async function listTemplates(): Promise<SimulationTemplate[]> {
  const { data } = await apiClient.get<SimulationTemplate[]>('/templates');
  return data;
}

export async function getTemplate(id: number): Promise<SimulationTemplate> {
  const { data } = await apiClient.get<SimulationTemplate>(`/templates/${id}`);
  return data;
}

export async function createTemplate(
  input: SimulationTemplateCreateInput,
): Promise<SimulationTemplate> {
  const { data } = await apiClient.post<SimulationTemplate>('/templates', input);
  return data;
}

export async function updateTemplate(
  id: number,
  patch: SimulationTemplatePatchInput,
): Promise<SimulationTemplate> {
  const { data } = await apiClient.patch<SimulationTemplate>(`/templates/${id}`, patch);
  return data;
}

export async function deleteTemplate(id: number): Promise<void> {
  await apiClient.delete(`/templates/${id}`);
}
