/* Fake SI
 * Returns API results as if the GSW OKC WCF game is about to start
 */

var jsonfile = require('jsonfile');

var proto = FakeSI.prototype;

function FakeSI(gameids) {
    this._current_key = 1;
    this._directory = "/home/ubuntu/workspace/okcgsw/";
    this._index = null;
    
    var setIndex = 
        (function(err, data) {
            if (err) {
                console.error(err);
            }
            else {
                this._index = data;
            }
        }).bind(this);
        
    jsonfile.readFile(this._directory + "live/index-1464483777835.json", setIndex);
}

proto.poll = function(gameid, callback) {
    if (this._index == null) {
        callback("index not initialized, please wait", null)
    }
    else {
        var name = this._index[this._current_key];
        jsonfile.readFile(this._directory + "live/" + name + ".json", function (err, data) {
            callback(err, data);
        })
        
        if (this._current_key < 897) {
            this._current_key++;
        }
    }
}

proto.getSchedule = function(callback) {
    jsonfile.readFile("../okcgsw/schedule/schedule-backup.json", function(err, data) {
        if (err) {
            console.error(err);
        }
        else {
            //create live schedule object, return that
            
            
        }
    })
}

proto.addSocket = function(new_socket) {
    //this._game_sockets.push(new);
};

module.exports = FakeSI;