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

const rentalCrawlerAdType =
  process.env.RENTAL_CRAWLER_AD_TYPE !== undefined
    ? CRAWLER_AD_TYPE[process.env.RENTAL_CRAWLER_AD_TYPE]
    : null;

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

const rentalIgnoredUsernames = [];

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

module.exports = {
  RENTAL_MAX_PAGES: parseInt(process.env.RENTAL_MAX_PAGES) || 500,
  RENTAL_MAX_RESULTS_PER_PAGE:
    parseInt(process.env.RENTAL_MAX_RESULTS_PER_PAGE) || 50,
  RENTAL_CRAWLER_AD_TYPE: rentalCrawlerAdType || CRAWLER_AD_TYPE.NONE,
  RENTAL_CRAWLER_AD_CATEGORIES: transformedRentalCrawlerAdCategories,
  RENTAL_IGNORED_USERNAMES: rentalIgnoredUsernames || [],
  RENTAL_DELAY_BETWEEN_PAGES:
    parseInt(process.env.RENTAL_DELAY_BETWEEN_PAGES) || 1000,
  RENTAL_FORCE_CRAWL: !!parseInt(process.env.RENTAL_FORCE_CRAWL)
};
