'use strict';

import Room from './modules/wt-room-sfu';
import Auth from './modules/wt-auth';
import Iot from './modules/wt-iot2';

import auth from './models/auth';
import room from './models/room';
import user from './models/user';
import asset from "./models/asset";
import system from "./models/system"
import iot from './models/iot'
import liveBarn from './models/live-barn';
import * as utils from './models/utils';

function WatchTogether(modules = {}, instanceType, debug, playerFactory, providerAuth) {
    this.username = null;
    this.userId = null;

    this.__instanceType = instanceType;
    this.__debug = debug;
    this.__privates = {
        playerFactory,
        providerAuth,
        room : modules.room,
        auth: modules.auth,
        iot: modules.iot,
    };

    this.setInstanceType = (newInstanceType) => this.__instanceType = newInstanceType;

    this.isReady = modules.room.whenInitialized;
    this.browser = modules.room.browser;
    this.browserDetails = modules.room.browserDetails

    this.auth = {...auth.call(this)};
    this.user = {...user.call(this)};
    this.room = {...room.call(this)};
    this.asset = {...asset.call(this)};
    this.system = {...system.call(this)}
    this.iot = {...iot.call(this)};
    this.liveBarn = {...liveBarn.call(this)};
    this.utils = utils;
}

let watchTogether = function ({debug = true, language = 'en-GB', storagePrefix = "reactoo_", apiUrl = null} = {}) {
    let room = new Room(debug);
    let auth = new Auth(debug, language, storagePrefix, apiUrl);
    let iot = new Iot(debug);

    return ({instanceType = 'reactooDemo', playerFactory = null, providerAuth = null} = {}) => {
        return new WatchTogether({room, auth, iot}, instanceType, debug, playerFactory, providerAuth);
    };

};

export default watchTogether

