checkSegmenting method

bool checkSegmenting()

Implementation

bool checkSegmenting() {
  // Fetch included list
  List<String>? includedListSet = DataManager().getIncludedList();
  List<String> includedList = [];
  if (includedListSet != null) {
    includedList.addAll(includedListSet);
    // Clear the data to avoid adding duplicate values on subsequent API calls
    DataManager().getIncludedList()?.clear();
  }

  // Fetch excluded list
  List<String>? excludedListSet = DataManager().getExcludedList();
  List<String> excludedList = [];
  if (excludedListSet != null) {
    excludedList.addAll(excludedListSet);
    // Clear the data to avoid adding duplicate values on subsequent API calls
    DataManager().getExcludedList()?.clear();
  }

  // Fetch contact response list
  List<String>? contactListSet = DataManager().getContactList();
  List<String> contactResponseList = [];
  if (contactListSet != null) {
    contactResponseList.addAll(contactListSet);
  }

  bool processEmbedSurvey = false;
  String inclueType = DataManager().getIncludeType();

  if (inclueType == 'all') {
    processEmbedSurvey = true;
  }

  // Check included segments
  if (includedList.isNotEmpty) {
    processEmbedSurvey = false;
    if (contactResponseList.isNotEmpty) {
      for (String segmentInContact in contactResponseList) {
        if (includedList.contains(segmentInContact)) {
          processEmbedSurvey = true;
          break;
        }
      }
    }
  }

  // Check excluded segments
  if (excludedList.isNotEmpty) {
    if (contactResponseList.isNotEmpty) {
      for (String segmentInContact in contactResponseList) {
        if (excludedList.contains(segmentInContact)) {
          processEmbedSurvey = false;
          break;
        }
      }
    }
  }

  return processEmbedSurvey;
}