enum Tab {
  Request = 'request',
  Response = 'response',
  Common = 'common',
  Templates = 'templates',
}

function capitalizeFirstLetter(str: string) {
  return str.charAt(0).toUpperCase() + str.slice(1);
}

function generateParentInteragencySearchQuery(
  searchFields: string[],
  searchText: string
): string {
  const constant = 'class==null';
  if (!searchText) {
    return constant;
  }
  const searchWords = [
    searchText,
    capitalizeFirstLetter(searchText),
    searchText.toLowerCase(),
    searchText.toUpperCase(),
  ];
  const search = searchFields
    .map((searchField) =>
      searchWords
        .map((searchWord: string) => `${searchField}=like=*${searchWord}*`)
        .join(' or ')
    )
    .join(' or ');
  const query = `${constant} and (${search})`;
  return query;
}

export { Tab, generateParentInteragencySearchQuery };