import type { TaskRecurrence, TaskRecurrenceWrite } from './dto/task-recurrence'

export function useTaskRecurrenceService() {
    const api = useApi()

    async function create(payload: TaskRecurrenceWrite): Promise<TaskRecurrence> {
        return api.post<TaskRecurrence>('/task_recurrences', payload as Record<string, unknown>, {
            toastSuccessKey: 'taskRecurrence.created',
        })
    }

    async function update(id: number, payload: Partial<TaskRecurrenceWrite>): Promise<TaskRecurrence> {
        return api.patch<TaskRecurrence>(`/task_recurrences/${id}`, payload as Record<string, unknown>, {
            toastSuccessKey: 'taskRecurrence.updated',
        })
    }

    async function remove(id: number): Promise<void> {
        await api.delete(`/task_recurrences/${id}`, {}, {
            toastSuccessKey: 'taskRecurrence.deleted',
        })
    }

    return { create, update, remove }
}
