import {ModuleWithProviders, NgModule} from '@angular/core';
import {API_BASE_PATH, ApiModuleConfig} from './api-module-config';

@NgModule()
export class ApiModule {
    public static forRoot(config: ApiModuleConfig = {}): ModuleWithProviders<ApiModule> {
        return {
            ngModule: ApiModule,
            providers: [
                config.basePath !== undefined
                    ? {provide: API_BASE_PATH, useValue: config.basePath}
                    : {provide: API_BASE_PATH, useValue: '.'},
            ],
        };
    }
}
