import { NgModule, ModuleWithProviders, SkipSelf, Optional } from '@angular/core';
import { Configuration } from '../configuration';
import { HttpClient } from '@angular/common/http';


import { ApplicantService } from './applicant.service';
import { ApplicationService } from './application.service';
import { AuthorizationService } from './authorization.service';
import { CompanyService } from './company.service';
import { JobPositionService } from './jobPosition.service';
import { JobPositionCategoryService } from './jobPositionCategory.service';
import { UserService } from './user.service';

@NgModule({
  imports:      [],
  declarations: [],
  exports:      [],
  providers: [
    ApplicantService,
    ApplicationService,
    AuthorizationService,
    CompanyService,
    JobPositionService,
    JobPositionCategoryService,
    UserService ]
})
export class ApiModule {
    public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders<any> {
        return {
            ngModule: ApiModule,
            providers: [ { provide: Configuration, useFactory: configurationFactory } ]
        };
    }

    constructor( @Optional() @SkipSelf() parentModule: ApiModule,
                 @Optional() http: HttpClient) {
        if (parentModule) {
            throw new Error('ApiModule is already loaded. Import in your base AppModule only.');
        }
        if (!http) {
            throw new Error('You need to import the HttpClientModule in your AppModule! \n' +
            'See also https://github.com/angular/angular/issues/20575');
        }
    }
}
