"use strict";
const { CRAWLER_AD_TYPE, AD_CATEGORY } = require("../../common/enums");

const saljicCrawlerAdType =
  process.env.SALJIC_CRAWLER_AD_TYPE !== undefined
    ? CRAWLER_AD_TYPE[process.env.SALJIC_CRAWLER_AD_TYPE]
    : null;

const saljicParsedCrawlerAdCategories =
  process.env.SALJIC_CRAWLER_AD_CATEGORIES !== undefined
    ? process.env.SALJIC_CRAWLER_AD_CATEGORIES.split(",").map(category =>
        category.trim()
      )
    : ["FLAT", "HOUSE"];

const saljicIgnoredUsernames = [];

const transformedSaljicCrawlerAdCategories = saljicParsedCrawlerAdCategories
  .map(categoryName =>
    AD_CATEGORY[categoryName] ? AD_CATEGORY[categoryName].id : undefined
  )
  .filter(category => !!category);

module.exports = {
  SALJIC_MAX_PAGES: parseInt(process.env.SALJIC_MAX_PAGES) || 100,
  SALJIC_MAX_RESULTS_PER_PAGE:
    parseInt(process.env.SALJIC_MAX_RESULTS_PER_PAGE) || 5000,
  SALJIC_CRAWLER_AD_TYPE: saljicCrawlerAdType || CRAWLER_AD_TYPE.NONE,
  SALJIC_CRAWLER_AD_CATEGORIES: transformedSaljicCrawlerAdCategories,
  SALJIC_IGNORED_USERNAMES: saljicIgnoredUsernames || [],
  SALJIC_DELAY_BETWEEN_PAGES:
    parseInt(process.env.SALJIC_DELAY_BETWEEN_PAGES) || 1000,
  SALJIC_FORCE_CRAWL: !!parseInt(process.env.SALJIC_FORCE_CRAWL)
};
