import type { HistoryEntry } from '~/types' export const useHistory = (clientId: number) => { const entries = ref([]) const fetchEntries = async (): Promise => { const response = await useApiFetch<{ data: HistoryEntry[] }>(`/api/clients/${clientId}/history`) entries.value = response.data } const addEntry = async (payload: { history_entry_type_id: number body: string occurred_at: string | null }): Promise => { await useApiFetch(`/api/clients/${clientId}/history`, { method: 'POST', body: payload, }) await fetchEntries() } const updateEntry = async ( id: number, payload: { body: string; occurred_at: string | null } ): Promise => { await useApiFetch(`/api/history/${id}`, { method: 'PUT', body: payload, }) await fetchEntries() } const deleteEntry = async (id: number): Promise => { await useApiFetch(`/api/history/${id}`, { method: 'DELETE', }) entries.value = entries.value.filter(e => e.id !== id) } return { entries, fetchEntries, addEntry, updateEntry, deleteEntry } }