export { applyAdditionalDriversToReservation, calculateAdditionalDriverCharge } from '../../services/additionalDriverService'

import * as repo from './reservation.repo'

export async function approveAdditionalDriver(
  reservationId: string,
  driverId: string,
  companyId: string,
  approved: boolean,
  note: string | undefined,
  approvedBy: string,
) {
  const driver = await repo.findAdditionalDriver(driverId, reservationId, companyId)
  return repo.updateAdditionalDriver(driver.id, {
    approvedAt:   approved ? new Date() : null,
    approvedBy:   approved ? approvedBy : null,
    approvalNote: note ?? driver.approvalNote,
  })
}
