/**
   * This method is going to get the printer type of the current model based on the information on
   * SystemDefinitions parsed object.
   *
   * @param linkToModel
   * @param systemDefinitionsParsed
   * @param statusMessagingList
   * @return
   */
  private static String getPrinterType(
      String linkToModel,
      ParseOutputObject systemDefinitionsParsed,
      List<StatusMessage> statusMessagingList) {
    String res = "";

    for (DataObject dataObject : systemDefinitionsParsed.getDataByColName("Color Models")) {
      if (linkToModel.equalsIgnoreCase(dataObject.getData())) {
        res = "Color";
        break;
      }
    }

    if (res.isEmpty()) {
      for (DataObject dataObject : systemDefinitionsParsed.getDataByColName("BW Models")) {
        if (linkToModel.equalsIgnoreCase(dataObject.getData())) {
          res = "BW";
          break;
        }
      }
    }

    return res;
  }
  /**
   * This method is going to build the map of OptionSetIdNumbers to keep the control of the global
   * optionSetIdNumbers from Panels.txt file since in that file we'll find all tha panels available
   * for the current rp3 project and that is our starting point to store all the available Panels.
   *
   * @param inputDto
   * @return
   */
  public static Map<String, OptionSetIdNumber> getOptionSetIdNumber(
      GetOptionSetIdNumberDto inputDto) {
    Map<String, OptionSetIdNumber> mapOptionSetIdNumber =
        new LinkedHashMap<String, OptionSetIdNumber>();

    if (LOG.isDebugEnabled()) {
      LOG.debug("UtilityOptionSetIdNumber getOptionSetIdNumber() inputDto : " + inputDto);
    }

    if (inputDto == null
        || inputDto.getStatusMessagingList() == null
        || inputDto.getDataObjectPanels() == null) {
      throw new IllegalArgumentException(
          "UtilityOptionSetIdNumber getOptionSetIdNumber() invalid input object : " + inputDto);
    }

    try {
      int rowPanelNumber = 0;
      int lastRowNumbr = 0;

      if (!inputDto
          .getDataObjectPanels()
          .getDataByColName(MsgConstants.UOSIN.QQ_PANELS_TITLE_COL_NAME.toString())
          .isEmpty()) {

        for (DataObject iter :
            inputDto
                .getDataObjectPanels()
                .getDataByColName(MsgConstants.UOSIN.QQ_PANELS_TITLE_COL_NAME.toString())) {
          if (iter.getRowNum() > (lastRowNumbr + 1)) break;

          rowPanelNumber++;
          lastRowNumbr++;
          OptionSetIdNumber valueDto = new OptionSetIdNumber();
          valueDto.setPageNumber(rowPanelNumber);
          valueDto.setOptionSetId(0);
          mapOptionSetIdNumber.put(iter.getData(), valueDto);
        }

      } else {
        StatusMessage statusMessage =
            new StatusMessage(
                Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_METHOD,
                MsgConstants.UOSIN.STATUS_MSG_WARNING_PANELS_WITHOUT_COLUMN_DATA,
                UtilityStatusMessage.getList(MsgConstants.UOSIN.QQ_PANELS_TITLE_COL_NAME),
                Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_WARNING);
        inputDto.getStatusMessagingList().add(statusMessage);
      }

      if (!inputDto
          .getDataObjectPanels()
          .getDataByColName(MsgConstants.UOSIN.PANELS_TITLE_COL_NAME.toString())
          .isEmpty()) {

        for (DataObject iter :
            inputDto
                .getDataObjectPanels()
                .getDataByColName(MsgConstants.UOSIN.PANELS_TITLE_COL_NAME.toString())) {
          if (iter.getRowNum() > (lastRowNumbr + 1)) break;

          rowPanelNumber++;
          lastRowNumbr++;

          OptionSetIdNumber valueDto = new OptionSetIdNumber();
          valueDto.setPageNumber(rowPanelNumber);
          valueDto.setOptionSetId(0);
          mapOptionSetIdNumber.put(iter.getData(), valueDto);
        }

      } else {
        StatusMessage statusMessage =
            new StatusMessage(
                Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_METHOD,
                MsgConstants.UOSIN.STATUS_MSG_WARNING_PANELS_WITHOUT_COLUMN_DATA,
                UtilityStatusMessage.getList(MsgConstants.UOSIN.PANELS_TITLE_COL_NAME),
                Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_WARNING);
        inputDto.getStatusMessagingList().add(statusMessage);
      }

      if (!mapOptionSetIdNumber.isEmpty()) {
        OptionSetIdNumber obj =
            (OptionSetIdNumber)
                mapOptionSetIdNumber.values().toArray()[mapOptionSetIdNumber.size() - 1];
        obj.setLastPage(true);

        // Now we are going to add the end template records
        Map<String, String> endTemplateMap = new LinkedHashMap<String, String>();
        Set<String> listEndTemplatePages = new LinkedHashSet<String>();
        for (String keyPrinter : inputDto.getTemplateEndPatternBaseDataDto().keySet()) {
          Map<String, BaseDataDto> mapEndBaseData =
              inputDto.getTemplateEndPatternBaseDataDto().get(keyPrinter);
          for (Map.Entry<String, BaseDataDto> baseDataDto : mapEndBaseData.entrySet()) {
            if (LOG.isDebugEnabled()) {
              LOG.debug(
                  "UtilityOptionSetIdNumber getOptionSetIdNumber() keyPrinter "
                      + keyPrinter
                      + " baseDataDto.getPage() : "
                      + baseDataDto.getValue().getPage());
            }
            listEndTemplatePages.add(baseDataDto.getValue().getPage());
          }
        }

        if (LOG.isDebugEnabled()) {
          LOG.debug(
              "UtilityOptionSetIdNumber getOptionSetIdNumber() listEndTemplatePages : "
                  + listEndTemplatePages);
        }

        boolean firstEndEndTemplateLoaded = false;
        for (String listEndTemplatePage : listEndTemplatePages) {
          OptionSetIdNumber valueDto = new OptionSetIdNumber();
          rowPanelNumber++;
          valueDto.setPageNumber(rowPanelNumber);
          valueDto.setOptionSetId(0);
          if (firstEndEndTemplateLoaded == false) {
            valueDto.setFirstEndTemplateRow(true);
            firstEndEndTemplateLoaded = true;
          }
          mapOptionSetIdNumber.put(listEndTemplatePage, valueDto);
        }

        OptionSetIdNumber objEndTemplate =
            (OptionSetIdNumber)
                mapOptionSetIdNumber.values().toArray()[mapOptionSetIdNumber.size() - 1];
        objEndTemplate.setLastEndTemplateRow(true);
      }

    } catch (RuntimeException re) {
      LOG.error("Error UtilityOptionSetIdNumber getOptionSetIdNumber() " + re.getMessage(), re);
      StatusMessage statusMessage =
          new StatusMessage(
              Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_METHOD,
              MsgConstants.UOSIN.STATUS_MSG_ERROR,
              UtilityStatusMessage.getList(re.getMessage()),
              Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_EXCEPTION);
      inputDto.getStatusMessagingList().add(statusMessage);
    }

    List<StatusMessage> listError =
        UtilityStatusMessage.getErrorsMessages(inputDto.getStatusMessagingList());
    if (listError == null || listError.isEmpty()) {
      StatusMessage statusMessage =
          new StatusMessage(
              Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_METHOD,
              MsgConstants.UOSIN.STATUS_MSG_OK,
              UtilityStatusMessage.getList(""),
              Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_NO_ERROR);
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug(
          "UtilityOptionSetIdNumber getOptionSetIdNumber() mapOptionSetIdNumber : "
              + mapOptionSetIdNumber);
    }

    return mapOptionSetIdNumber;
  }
  /**
   * This method is going to get all the list of bw & printers models that are stored on the
   * SystemDefinitions text file.
   *
   * @param inputDto
   * @return
   */
  public Map<String, List<String>> getBuildPrintersTypes(GetBuildPrintersTypesInputDto inputDto) {
    Map<String, List<String>> res = new HashMap<String, List<String>>();

    if (LOG.isDebugEnabled()) {
      LOG.debug("UtilityPrinterTypes getBuildPrintersTypes() inputDto : " + inputDto);
    }

    if (inputDto == null
        || inputDto.getStatusMessagingList() == null
        || inputDto.getDataObjectSystemDefinitions() == null) {
      throw new IllegalArgumentException(
          "UtilityPrinterTypes getBuildPrintersTypes() invalid input object : " + inputDto);
    }

    try {

      if (LOG.isDebugEnabled()) {
        LOG.debug(
            "UtilityPrinterTypes getBuildPrintersTypes() geeting CONSTANTS.COLOR_MODELS : "
                + CONSTANTS.COLOR_MODELS);
      }

      if (inputDto
              .getDataObjectSystemDefinitions()
              .getDataByColName(CONSTANTS.COLOR_MODELS.toString())
              .isEmpty()
          == false) {
        List<String> list = new ArrayList<String>();
        for (DataObject dataObject :
            inputDto
                .getDataObjectSystemDefinitions()
                .getDataByColName(CONSTANTS.COLOR_MODELS.toString())) {
          list.add(dataObject.getData());
        }
        res.put(CONSTANTS.COLOR_MODELS.toString(), list);
      } else {
        StatusMessage statusMessage =
            new StatusMessage(
                Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_METHOD.toString(),
                STATUS_MSG_CODES.STATUS_MSG_ERROR_NO_COLOR_MODELS_COLUMN_DATA.toString(),
                Arrays.asList(new String[] {CONSTANTS.COLOR_MODELS.toString()}),
                Integer.valueOf(Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_WARNING.toString()));
        inputDto.getStatusMessagingList().add(statusMessage);
      }

      if (inputDto
              .getDataObjectSystemDefinitions()
              .getDataByColName(CONSTANTS.BW_MODELS.toString())
              .isEmpty()
          == false) {
        List<String> list = new ArrayList<String>();
        for (DataObject dataObject :
            inputDto
                .getDataObjectSystemDefinitions()
                .getDataByColName(CONSTANTS.BW_MODELS.toString())) {
          list.add(dataObject.getData());
        }
        res.put(CONSTANTS.BW_MODELS.toString(), list);
      } else {
        StatusMessage statusMessage =
            new StatusMessage(
                Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_METHOD.toString(),
                STATUS_MSG_CODES.STATUS_MSG_ERROR_NO_BW_MODELS_COLUMN_DATA.toString(),
                Arrays.asList(new String[] {CONSTANTS.BW_MODELS.toString()}),
                Integer.valueOf(Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_WARNING.toString()));
        inputDto.getStatusMessagingList().add(statusMessage);
      }

    } catch (RuntimeException re) {
      LOG.error("Error UtilityPrinterTypes getBuildPrintersTypes() " + re.getMessage(), re);
      StatusMessage statusMessage =
          new StatusMessage(
              Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_METHOD.toString(),
              STATUS_MSG_CODES.STATUS_MSG_ERROR.toString(),
              Arrays.asList(new String[] {""}),
              Integer.valueOf(Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_EXCEPTION.toString()));
      inputDto.getStatusMessagingList().add(statusMessage);
    } finally {
      List<StatusMessage> listError =
          UtilityStatusMessage.getErrorsMessages(inputDto.getStatusMessagingList());
      if (listError.isEmpty()) {
        StatusMessage statusMessage =
            new StatusMessage(
                Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_METHOD.toString(),
                STATUS_MSG_CODES.STATUS_MSG_OK.toString(),
                Arrays.asList(
                    new String[] {
                      CONSTANTS.BW_MODELS.toString(), CONSTANTS.COLOR_MODELS.toString()
                    }),
                Integer.valueOf(Rp3Constants.CODES_MSG.STATUS_MSG_LEVEL_NO_ERROR.toString()));
        inputDto.getStatusMessagingList().add(statusMessage);
      }
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("UtilityPrinterTypes getBuildPrintersTypes() res : " + res);
    }

    return res;
  }