'use strict';

var ConfigBuilder = require('../ConfigBuilder');
var PagePropertyBuilder = require('../PagePropertyBuilder');
var TwitterCardFactory = require('../../modules/TwitterCard/Factory');
var TwitterCardSummaryLargeImageBuilder = require('./SummaryLargeImageBuilder');

class TwitterCardFactoryBuilder {

    constructor(obj) {
        this.config = (obj && obj.config) || new ConfigBuilder().build();
        this.page = obj.page;

        this.pageProperty = (obj && obj.pageProperty) || new PagePropertyBuilder({page: this.page}).build();
        this.cardType = (obj && obj.cardType) || 'summary_large_image';

        this.setTwitterCard();
    }

    setTwitterCard() {
        if (this.cardType === 'summary_large_image') {
            this.twitterCard = new TwitterCardSummaryLargeImageBuilder({page: this.page}).build();
        }
    }

    build() {
        return new TwitterCardFactory(
            this.config,
            this.twitterCard
        );
    }

}

module.exports = TwitterCardFactoryBuilder;
@@ -192,89 +192,8 @@
 y');
-%0Avar TwitterCardSummaryLargeImageBuilder = require('./SummaryLargeImageBuilder');
 %0A%0Acl
@@ -563,16 +563,29 @@
 terCard(
+this.cardType
 );%0A    %7D
@@ -582,24 +582,164 @@
 pe);%0A    %7D%0A%0A
+    getModules() %7B%0A        return %5B%0A            %7B cardType: 'summary_large_image', source: './SummaryLargeImageBuilder' %7D%0A        %5D;%0A    %7D%0A%0A
     setTwitt
@@ -745,16 +745,24 @@
 terCard(
+cardType
 ) %7B%0A    
@@ -769,55 +769,158 @@
     
-if (
 this.
-cardType === 'summary_large_image') %7B%0A
+getModules().forEach((module) =%3E %7B%0A            if (module.cardType === cardType) %7B%0A                var twitterCard = require(module.source);%0A    
     
@@ -946,25 +946,25 @@
 rCard = new 
-T
+t
 witterCardSu
@@ -965,32 +965,8 @@
 Card
-SummaryLargeImageBuilder
 (%7Bpa
@@ -998,17 +998,33 @@
         
-%7D
+    %7D%0A        %7D);
 %0A    %7D%0A%0A

Refactor TwitterCardFactoryBuilder module