import {
  ApplicationConfig,
  provideBrowserGlobalErrorListeners,
  isDevMode
} from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideHttpClient, withInterceptors } from '@angular/common/http';
import { authTokenInterceptor } from './domains/authentication/infrastructure/auth-token.interceptor';
import { provideTranslateService } from '@ngx-translate/core';
import { provideStore } from '@ngrx/store';
import { provideEffects } from '@ngrx/effects';
import { provideStoreDevtools } from '@ngrx/store-devtools';

import { routes } from './app.routes';
import { messagesReducer } from './store/messages/messages.reducer';
import { usersReducer } from './store/users/users.reducer';
import { roomsReducer } from './store/rooms/rooms.reducer';
import { NotificationsEffects } from './domains/notifications';
import { CustomEmojiSyncEffects } from './domains/custom-emoji';
import { MessagesEffects } from './store/messages/messages.effects';
import { MessagesSyncEffects } from './store/messages/messages-sync.effects';
import { UserAvatarEffects } from './store/users/user-avatar.effects';
import { UsersEffects } from './store/users/users.effects';
import { RoomsEffects } from './store/rooms/rooms.effects';
import { RoomMembersSyncEffects } from './store/rooms/room-members-sync.effects';
import { RoomStateSyncEffects } from './store/rooms/room-state-sync.effects';
import { RoomSettingsEffects } from './store/rooms/room-settings.effects';
import { STORE_DEVTOOLS_MAX_AGE } from './core/constants';
import { DEFAULT_APP_LOCALE } from './core/i18n';

/** Root application configuration providing routing, HTTP, NgRx store, and devtools. */
export const appConfig: ApplicationConfig = {
  providers: [
    provideBrowserGlobalErrorListeners(),
    provideRouter(routes),
    provideHttpClient(withInterceptors([authTokenInterceptor])),
    provideTranslateService({
      fallbackLang: DEFAULT_APP_LOCALE,
      lang: DEFAULT_APP_LOCALE
    }),
    provideStore({
      messages: messagesReducer,
      users: usersReducer,
      rooms: roomsReducer
    }),
    provideEffects([
      NotificationsEffects,
      CustomEmojiSyncEffects,
      MessagesEffects,
      MessagesSyncEffects,
      UserAvatarEffects,
      UsersEffects,
      RoomsEffects,
      RoomMembersSyncEffects,
      RoomStateSyncEffects,
      RoomSettingsEffects
    ]),
    provideStoreDevtools({
      maxAge: STORE_DEVTOOLS_MAX_AGE,
      logOnly: !isDevMode(),
      autoPause: true,
      trace: false
    })
  ]
};
