import type { EmployeeLeaveSummary } from './dto/employee-leave-summary'

export const getEmployeeLeaveSummary = async (employeeId: number, year?: number, phaseId?: number) => {
  const api = useApi()
  const query: Record<string, string> = {}
  if (year) query.year = String(year)
  if (phaseId !== undefined) query.phaseId = String(phaseId)

  return api.get<EmployeeLeaveSummary>(`/employees/${employeeId}/leave-summary`, query, { toast: false })
}

export const updateFractionedDays = async (employeeId: number, fractionedDays: number, year?: number) => {
  const api = useApi()
  const body: Record<string, unknown> = { fractionedDays }
  if (year) body.year = year

  return api.patch(`/employees/${employeeId}/fractioned-days`, body)
}

export const updatePaidLeaveDays = async (employeeId: number, paidLeaveDays: number, year?: number) => {
  const api = useApi()
  const body: Record<string, unknown> = { paidLeaveDays }
  if (year) body.year = year

  return api.patch(`/employees/${employeeId}/paid-leave-days`, body)
}

