/**
 * One way of refactoring. There are probably tons of additional possibilites. For example i18n could be implemented.
 */

namespace Alax {
  'use strict';

  const ANSWERS = {
    /**
     * Answer for the contact address
     */
    ADDRESS: 'Oliver Schiessl, Frauenbr├╝nnlstra├če 86, 94315 Straubing, info@alax.de',

    /**
     * Issue map providing the answers for the issue keywords
     */
    ISSUE: new Map([
      ['website', 'yes'],
      ['backend', 'Of course!'],
      ['rest service', 'No Problem!'],
      ['code structure', 'With pleasure!'],
      ['architecture', 'With pleasure!'],
    ]),

    /**
     * Framework map providing the answers for the issue keywords
     */
    FRAMEWORK: new Map([
      ['jquery', 'If I have to, but are you sure, that you are up to date? ;-)'],
      ['angular', 'yes'],
      ['angular2', 'Of course!'],
      ['nodejs', 'The best way to go!'],
    ]),

    /**
     * Language map providing the answers for the issue keywords
     */
    LANGUAGE: new Map([
      ['html5', 'Yes!'],
      ['css3', 'Indeed!'],
      ['sass', 'Indeed!'],
      ['less', 'Indeed!'],
      ['javascript', 'For sure!'],
      ['typescript', 'Obviously!'],
    ]),

    /**
     * Standard answer, if no keyword is found
     */
    STANDARD: 'Maybe, but I always can help with my Network.',
  };
  
  /**
   * this class offers all possibilities for the customer
   */
  class QuestionAnswerer {

    /**
     * get the address of alax
     * @returns {string}
     */
    getAddressAnswer():string {
      return ANSWERS.ADDRESS;
    }

    /**
     * get the answer to an issue question
     * @param issue
     * @returns {string}
     */
    getIssueAnswer(issue:string) {
      return this.getAnswer(ANSWERS.ISSUE, issue);
    }

    /**
     * get the answer to a framework question
     * @param framework
     * @returns {string}
     */
    getFrameworkAnswer(framework:string) {
      return this.getAnswer(ANSWERS.FRAMEWORK, framework);
    }

    /**
     * get the answer to a language question
     * @param language
     * @returns {string}
     */
    getLanguageAnswer(language:string) {
      return this.getAnswer(ANSWERS.LANGUAGE, language);
    }

    /**
     * provide answering logic for several different question types
     * @param map
     * @param question
     * @returns {string}
     */
    private getAnswer(map:Map, question:string) {
      for (const [key, value] of map) {
        if ((new RegExp(key, 'i')).test(question)) {
          return value;
        }
      }
      return ANSWERS.STANDARD;
    }
  }
}