"use strict";

const InterpolateStrategy = require('./syncStrategies/InterpolateStrategy');
const ClientPredictionStrategy = require('./syncStrategies/ClientPredictionStrategy');
const FrameSyncStrategy = require('./syncStrategies/FrameSyncStrategy');
const ExtrapolateStrategy = require('./syncStrategies/ExtrapolateStrategy');

class Synchronizer {

    constructor(clientEngine) {
        this.clientEngine = clientEngine;
    }

    // TODO:
    // The code below can surely be folded.  Maybe with a Proxy object.
    // or by adding the methods in a loop over each strategy name.

    set interpolateObjectSelector(selector) {
        if (!this.interpolateStrategy) {
            this.interpolateStrategy = new InterpolateStrategy(this.clientEngine);
        }
        this.interpolateStrategy.objectSelector = selector;
    }

    set clientPredictionSelector(selector) {
        if (!this.clientPredictionStrategy) {
            this.clientPredictionStrategy = new ClientPredictionStrategy(this.clientEngine);
        }
        this.clientPredictionStrategy.objectSelector = selector;
    }

    set frameSyncSelector(selector) {
        if (!this.frameSyncStrategy) {
            this.frameSyncStrategy = new FrameSyncStrategy(this.clientEngine);
        }
        this.frameSyncStrategy.objectSelector = selector;
    }

    set extrapolateObjectSelector(selector) {
        if (!this.extrapolateStrategy) {
            this.extrapolateStrategy = new ExtrapolateStrategy(this.clientEngine);
        }
        this.extrapolateStrategy.objectSelector = selector;
    }

}

module.exports = Synchronizer;

@@ -345,16 +345,270 @@
 izer %7B%0A%0A
+    // create a synchronizer instance%0A    //%0A    // options have sub-options for each synchronization strategy%0A    // options = %7B%0A    //     interpolate: %7B%7D,%0A    //     clientPrediction: %7B%7D,%0A    //     frameSync: %7B%7D,%0A    //     extrapolate: %7B%7D%0A    // %7D;%0A
     cons
@@ -627,16 +627,25 @@
 ntEngine
+, options
 ) %7B%0A    
@@ -682,16 +682,54 @@
 Engine;%0A
+        this.options = options %7C%7C %7B%7D;%0A
     %7D%0A%0A 
@@ -1039,32 +1039,58 @@
 his.clientEngine
+, this.options.interpolate
 );%0A        %7D%0A   
@@ -1326,32 +1326,63 @@
 his.clientEngine
+, this.options.clientPrediction
 );%0A        %7D%0A   
@@ -1595,32 +1595,56 @@
 his.clientEngine
+, this.options.frameSync
 );%0A        %7D%0A   
@@ -1784,32 +1784,32 @@
 lateStrategy) %7B%0A
-
             this
@@ -1872,16 +1872,42 @@
 ntEngine
+, this.options.extrapolate
 );%0A     

allow sync strategy options