import * as selectors from '../redux/selectors';

import { getFormMetadataCalculation } from './calculationsFromState';

const createRequestBody = (state) => {
  const id = selectors.idSelector(state);
  const formTemplateCategoryId = selectors.categorySelector(state);
  const account = selectors.accountSelector(state);
  const name = selectors.nameSelector(state);
  const title = selectors.titleSelector(state);
  const logo = selectors.imageSelector(state);

  const body = {
    formTemplateCategoryId,
    accountId: account.value || null,
    name,
    title,
    logo,
    metadata: JSON.stringify(getFormMetadataCalculation(state)),
  };

  if (id) {
    body.id = id;
  }

  return body;
};

export default createRequestBody;
