/**
   * @param verificationMapFromUnpackedFiles Map of BBI files names to their corresponding
   *     verifications
   * @param listOfBBIfiles List with BBI files extracted from the archive
   * @return List of DTOs containing BBI filename, verification id, outcome of parsing (true/false),
   *     and reason of rejection (if the bbi file was rejected)
   */
  private List<BBIOutcomeDTO> processListOfBBIFiles(
      Map<String, Map<String, String>> verificationMapFromUnpackedFiles,
      List<File> listOfBBIfiles,
      User calibratorEmployee)
      throws ParseException {
    List<BBIOutcomeDTO> resultsOfBBIProcessing = new ArrayList<>();

    for (File bbiFile : listOfBBIfiles) {
      Map<String, String> correspondingVerificationMap =
          verificationMapFromUnpackedFiles.get(bbiFile.getName());
      String correspondingVerification =
          correspondingVerificationMap.get(Constants.VERIFICATION_ID);
      BBIOutcomeDTO.ReasonOfRejection reasonOfRejection = null;
      if (correspondingVerification == null) {
        try {
          correspondingVerification =
              createNewVerificationFromMap(correspondingVerificationMap, calibratorEmployee);
          parseAndSaveBBIFile(bbiFile, correspondingVerification, bbiFile.getName());
          Verification verification = verificationService.findById(correspondingVerification);
          verification.setStatus(Status.CREATED_BY_CALIBRATOR);
          verificationService.saveVerification(verification);
        } catch (NoSuchElementException e) {
          reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.INVALID_COUNTER_SIZE_AND_SYMBOL;
          logger.info(e);
        } catch (Exception e) {
          reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.BBI_IS_NOT_VALID;
          logger.info(e);
        }
      } else {
        try {
          updateVerificationFromMap(correspondingVerificationMap, correspondingVerification);
          parseAndSaveBBIFile(bbiFile, correspondingVerification, bbiFile.getName());
        } catch (NoSuchElementException e) {
          reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.INVALID_COUNTER_SIZE_AND_SYMBOL;
          logger.info(e);
        } catch (IOException e) {
          reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.BBI_IS_NOT_VALID;
          logger.info(e);
        } catch (Exception e) {
          reasonOfRejection = BBIOutcomeDTO.ReasonOfRejection.INVALID_VERIFICATION_CODE;
          logger.info(e);
        }
      }
      if (reasonOfRejection == null) {
        resultsOfBBIProcessing.add(
            BBIOutcomeDTO.accept(bbiFile.getName(), correspondingVerification));
      } else {
        resultsOfBBIProcessing.add(
            BBIOutcomeDTO.reject(bbiFile.getName(), correspondingVerification, reasonOfRejection));
      }
    }
    return resultsOfBBIProcessing;
  }
  private void updateVerificationFromMap(
      Map<String, String> verificationData, String verificationId) throws Exception {

    Verification verification = verificationService.findById(verificationId);
    Counter counter = getCounterFromVerificationData(verificationData);
    verification.setCounter(counter);
  }
  private String createNewVerificationFromMap(
      Map<String, String> verificationData, User calibratorEmployee) throws ParseException {

    Address address =
        new Address(
            verificationData.get(Constants.REGION),
            verificationData.get(Constants.CITY),
            verificationData.get(Constants.STREET),
            verificationData.get(Constants.BUILDING),
            verificationData.get(Constants.FLAT));
    ClientData clientData =
        new ClientData(
            verificationData.get(Constants.FIRST_NAME),
            verificationData.get(Constants.LAST_NAME),
            verificationData.get(Constants.MIDDLE_NAME),
            verificationData.get(Constants.PHONE_NUMBER),
            address);

    Long calibratorOrganisationId = calibratorEmployee.getOrganization().getId();
    Organization calibrator = organizationService.getOrganizationById(calibratorOrganisationId);
    Counter counter = getCounterFromVerificationData(verificationData);
    Date date =
        new SimpleDateFormat(Constants.FULL_DATE).parse(verificationData.get(Constants.DATE));
    String verId =
        verificationService.getNewVerificationDailyIdByDeviceType(
            date, counter.getCounterType().getDevice().getDeviceType());
    Verification verification =
        new Verification(
            date,
            clientData,
            Status.CREATED_BY_CALIBRATOR,
            calibrator,
            calibratorEmployee,
            counter,
            verId);
    String verificationId = verification.getId();
    verificationService.saveVerification(verification);
    return verificationId;
  }