/** PUT /api/settings/carrier-rates/update — body: { id, ...CarrierRateInput } (only sent keys are written) */
import { withIdempiere } from '../../../utils/shipping/withIdempiere'
import fetchHelper from '../../../utils/fetchHelper'
import { CARRIER_RATE_MODEL, carrierRateBody } from '../../../utils/shipping/carrierRates'

export default defineEventHandler(withIdempiere(async (event, token) => {
  const body: any = await readBody(event)
  const id = Number(body?.id)
  if (!id) return { status: 400, message: 'id missing' }
  const { id: _id, ...rest } = body
  const res: any = await fetchHelper(event, `${CARRIER_RATE_MODEL}/${id}`, 'PUT', token, carrierRateBody(rest, false))
  return { ...res, status: 200, message: '' }
}))
