export function parseExtrasQuery(value) {
  const rawValue = Array.isArray(value) ? value.join(',') : String(value || '')

  return [...new Set(
    rawValue
      .split(',')
      .map((entry) => Number(String(entry || '').trim()))
      .filter((entry) => Number.isInteger(entry) && entry > 0),
  )]
}

export function buildExtrasPayload(extraIds) {
  return parseExtrasQuery(extraIds).map((extraId) => ({
    extra_id: extraId,
    quantity: 1,
  }))
}

export function buildExtrasQuery(extraIds) {
  const normalized = parseExtrasQuery(extraIds)

  return normalized.length ? normalized.join(',') : undefined
}
