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

import { APIKeysService } from './api/aPIKeys.service';
import { AccountLossesService } from './api/accountLosses.service';
import { ActivityLogsService } from './api/activityLogs.service';
import { AffiliatesService } from './api/affiliates.service';
import { AnalyticsEventTrackerService } from './api/analyticsEventTracker.service';
import { AppropriatenessQuestionnaireService } from './api/appropriatenessQuestionnaire.service';
import { AssetConverterService } from './api/assetConverter.service';
import { AuthService } from './api/auth.service';
import { BankAccountsService } from './api/bankAccounts.service';
import { BusinessesService } from './api/businesses.service';
import { CryptoAddressesService } from './api/cryptoAddresses.service';
import { DeviceAPIKeysService } from './api/deviceAPIKeys.service';
import { DynamicPoliciesService } from './api/dynamicPolicies.service';
import { MarketsService } from './api/markets.service';
import { MissingDepositsService } from './api/missingDeposits.service';
import { PoliciesService } from './api/policies.service';
import { PortfolioService } from './api/portfolio.service';
import { PriceMovementAlertsService } from './api/priceMovementAlerts.service';
import { PruService } from './api/pru.service';
import { PublicService } from './api/public.service';
import { RecurringPurchasesService } from './api/recurringPurchases.service';
import { ReportsService } from './api/reports.service';
import { StakingService } from './api/staking.service';
import { StatementsService } from './api/statements.service';
import { SupportCenterService } from './api/supportCenter.service';
import { TaxReportingService } from './api/taxReporting.service';
import { TransferFundsService } from './api/transferFunds.service';
import { TrustedContactsService } from './api/trustedContacts.service';
import { UserService } from './api/user.service';
import { WithdrawalsService } from './api/withdrawals.service';

@NgModule({
  imports:      [],
  declarations: [],
  exports:      [],
  providers: []
})
export class ApiModule {
    public static forRoot(configurationFactory: () => Configuration): ModuleWithProviders<ApiModule> {
        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');
        }
    }
}
