import type { ContractSuspension } from './dto/employee'

export const createSuspension = async (payload: {
  contractPeriodId: number
  startDate: string
  endDate?: string | null
  comment?: string | null
}) => {
  const api = useApi()
  return api.post<ContractSuspension>('/contract_suspensions', {
    contractPeriodId: payload.contractPeriodId,
    startDate: payload.startDate,
    endDate: payload.endDate ?? null,
    comment: payload.comment ?? null
  }, {
    toastSuccessKey: 'Suspension créée',
    toastErrorKey: 'Erreur lors de la création de la suspension'
  })
}

export const updateSuspension = async (
  id: number,
  payload: {
    startDate: string
    endDate?: string | null
    comment?: string | null
  }
) => {
  const api = useApi()
  return api.patch<ContractSuspension>(`/contract_suspensions/${id}`, {
    startDate: payload.startDate,
    endDate: payload.endDate ?? null,
    comment: payload.comment ?? null
  }, {
    toastSuccessKey: 'Suspension modifiée',
    toastErrorKey: 'Erreur lors de la modification de la suspension'
  })
}
