import api from './apiClient';

const Pattern = require('../model/pattern');

class JeniusService {
  _patterns = [];

  constructor() {
    this.initPatterns();
  }

  _addPattern(regexes, action) {
    const pattern = new Pattern(regexes, () => action);
    this._patterns.push(pattern);
  }

  _totalNumberOfTeams() {
    return Promise.resolve(12);
  }

  _getCurrentBalance() {
    return api.getCurrentBalance('90010000526').then(data => data.balance);
  }

  getPatternMatches() {
    return this._patterns;
  }

  initPatterns() {

    const patterns = [
      {
        regex: [/^teams$/],
        action: this._totalNumberOfTeams()
          .then((number) => `Number of TEAMS = ${number}`)
      }
    ];

    for(let pattern of patterns) {
      this._addPattern(pattern.regex, pattern.action);
    }
  }
}

export default JeniusService;


@@ -701,16 +701,169 @@
 %0A      %7D
+,%0A      %7B%0A        regex: %5B/balance/%5D,%0A        action: this._getCurrentBalance()%0A          .then((balance) =%3E %60Your current balance: $%7Bbalance%7D%60)%0A      %7D%0A
 %0A    %5D;%0A

add current balance