import { get, pick } from 'lodash';

export default function (resultCompany, key, { leasingPeriod }) {
  if (!resultCompany || Object.keys(resultCompany).length === 0) {
    return;
  }

  const dataFromResult = pick(
    resultCompany,
    ['message', 'requestId', 'skCalcId'],
    '',
  );

  const sumsFromResult = pick(resultCompany, ['totalFranchise'], 0);

  const kaskoSumSource =
    leasingPeriod <= 16 ? 'kaskoSum' : 'paymentPeriods[0].kaskoSum';
  const kaskoSum = get(resultCompany, kaskoSumSource, 0);

  return {
    key,
    ...dataFromResult,
    ...sumsFromResult,
    kaskoSum,
  };
}
