import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core';
import { NativeScriptHttpClientModule } from '@nativescript/angular';
import { NgxsModule } from '@ngxs/store';
import { AuthGuard } from '~/core/services/auth-guard.service';
import { HomeGuard } from '~/core/services/home-guard.service';
import { LoginDataService } from '~/core/services/login-data.service';
import { PhoneContactService } from '~/core/services/phone-contact.service';
import { UtilsService } from '~/core/services/utils.service';
import { WebApiService } from '~/core/services/web-api.service';
import { AppState } from '~/core/state-mgmt/app.state';
import { ActionBarScrollSyncService } from './services/action-bar-scroll-sync.service';
@NgModule({
    imports: [
        NativeScriptHttpClientModule,
        NgxsModule.forRoot([
            AppState
        ])
    ]
})
export class CoreModule {
    static forRoot(): ModuleWithProviders {
        return {
            ngModule: CoreModule,
            providers: [
                LoginDataService,
                WebApiService,
                PhoneContactService,
                UtilsService,
                AuthGuard,
                HomeGuard,
                ActionBarScrollSyncService,
            ]
        };
    }

    constructor(
        @Optional()
        @SkipSelf()
        parentModule: CoreModule) {
        if (parentModule) {
            throw new Error(
                `CoreModule is already loaded. It can only be imported inside of the AppModule!`
            );

        }
    }
}
