import {IFactory} from '../interfaces/commands/IFactory';
import {IFactory as IAppFactory} from '../interfaces/IFactory';
import {IAppCommands} from '../interfaces/commands/IAppCommands';
import {AppCommands} from '../commands/AppCommands';
import {Helpers} from '@common/admin/Helpers';

export class Factory implements IFactory {
    
    protected appFactory:IAppFactory;

    protected appCommands:IAppCommands = null;

    protected conf:any = {};

    public init(conf:any = {}): void
    {
        this.conf = {
            'appCommands': null
        }
        Helpers.objectReplaceRecursive(this.conf, conf);
    }

    public setAppFactory(factory:IAppFactory): void
    {
        this.appFactory = factory;
    }

    public getAppCommands(): IAppCommands
    {
        if(this.appCommands === null){
            this.appCommands = this.conf.appCommands || new AppCommands();
        }
        return this.appCommands;
    }
}