import { BUDGET_CONTROL_STATUS_OFF, GEO_ACTION_INCLUDE, PACING_MINUTELY, STATUS_PAUSED } from '../constants';

function rowToRequestBody(row, budgetControlStatus) {
  const requestData = {
    uid: row.id,
    startDateTime: row.startDateTime,
    endDateTime: row.endDateTime,
    device: row.device.map((o) => o.value || o),
    geo: {
      geo: row.geo.map((o) => o.value || o),
      action: GEO_ACTION_INCLUDE,
    },
    viewsBudget: +row.viewsBudget,
  };

  if (budgetControlStatus === BUDGET_CONTROL_STATUS_OFF) {
    delete requestData.viewsBudget;
    requestData.pacing = PACING_MINUTELY;
  }

  if (row.status === STATUS_PAUSED) {
    delete requestData.geo;
    delete requestData.device;
    delete requestData.startDateTime;
  }

  return requestData;
}

export default rowToRequestBody;
