import { combineReducers } from '@reduxjs/toolkit';

import { slice as sliceCcFiles } from '@/modules/@common/ccFiles/redux/slices';
import { slice as sliceGql } from '@/modules/@common/gql/redux/slices';
import { slice as sliceInit } from '@/modules/@common/init/redux/slices';
import { slice as sliceLocation } from '@/modules/@common/location/redux/slices';
import { slice as sliceMonitoring } from '@/modules/@common/monitoring/redux/slices';
import { slice as sliceNotify } from '@/modules/@common/notify/redux/slices';
import { slice as sliceRequest } from '@/modules/@common/request/redux/slices';
import { slice as sliceToken } from '@/modules/@common/token/redux/slices';
import { slice as sliceUser } from '@/modules/@common/user/redux/slices';
import { slice as sliceAccountsEditor } from '@/modules/accounts/Editor/redux/slices';
import { slice as sliceAccountsList } from '@/modules/accounts/List/redux/slices';
import { slice as sliceAdServersEditor } from '@/modules/adServers/Editor/redux/slices';
import { slice as sliceAdServersList } from '@/modules/adServers/List/redux/slices';
import { slice as sliceAdvertiserEditor } from '@/modules/advertisers/Editor/redux/slices';
import { slice as sliceAdvertisers } from '@/modules/advertisers/List/redux/slices';
import { slice as sliceAnalyticsCustomReports } from '@/modules/analytics/customReports/redux/slices';
import { slice as sliceAnalyticsGeneral } from '@/modules/analytics/general/redux/slices';
import { slice as sliceAnalyticsLiveDashboard } from '@/modules/analytics/liveDashboard/redux/slices';
import { slice as sliceAnalyticsMonetization } from '@/modules/analytics/monetization/redux/slices';
import { slice as sliceAnalyticsRevenueOverview } from '@/modules/analytics/revenueOverview/List/redux/slices';
import { slice as sliceAnalyticsVideoContentPerformance } from '@/modules/analytics/videoContentPerformance/redux/slices';
import { slice as sliceAuthLayout } from '@/modules/auth/common/redux/slices';
import { slice as sliceAuthCreateResetPassword } from '@/modules/auth/CreateResetPassword/redux/slices';
import { slice as sliceAuthGuestActivation } from '@/modules/auth/GuestActivation/redux/slices';
import { slice as sliceLogin } from '@/modules/auth/Login/redux/slices';
import { slice as sliceConfiguration } from '@/modules/configuration/redux/slices';
import { slice as sliceContentOwnersEditor } from '@/modules/contentOwners/Editor/redux/slices';
import { slice as sliceContentOwnersList } from '@/modules/contentOwners/List/redux/slices';
import { slice as sliceCustomDashboardsEditor } from '@/modules/customReports/Editor/redux/slices';
import { slice as sliceCustomDashboards } from '@/modules/customReports/List/redux/slices';
import { slice as sliceAiWorkbenchCreateVideo } from '@/modules/editorial/aiWorkbench/AiWorkbench/components/CreateVideoForm/redux/slices';
import { slice as sliceAiWorkbench } from '@/modules/editorial/aiWorkbench/AiWorkbench/redux/slices';
import { slice as sliceAiWorkbenchChapters } from '@/modules/editorial/aiWorkbench/Chapters/redux/slices';
import { slice as sliceAiWorkbenchDescription } from '@/modules/editorial/aiWorkbench/Description/redux/slices';
import { slice as sliceAiWorkbenchHighlights } from '@/modules/editorial/aiWorkbench/Highlights/redux/slices';
import { slice as sliceAiWorkbenchSlides } from '@/modules/editorial/aiWorkbench/Slides/redux/slices';
import { slice as sliceAiWorkbenchTagLog } from '@/modules/editorial/aiWorkbench/TagLog/redux/slices';
import { slice as sliceAiWorkbenchThumbnail } from '@/modules/editorial/aiWorkbench/Thumbnail/redux/slices';
import { slice as sliceAiWorkbenchTranslations } from '@/modules/editorial/aiWorkbench/Translations/redux/slices';
import { slice as sliceBulkShareActions } from '@/modules/editorial/bulkActions/components/BulkActionShare/redux/slices';
import { slice as sliceBulkActions } from '@/modules/editorial/bulkActions/redux/slices';
import { slice as sliceEditorialPlayerPreview } from '@/modules/editorial/common/components/PlayerPreview/redux/slices';
import { slice as sliceTrimVideo } from '@/modules/editorial/common/components/trimVideo/redux/slices';
import { slice as sliceDetailsNameSpace } from '@/modules/editorial/editorialSearch/redux/slices';
import { slice as sliceEditorialSearch } from '@/modules/editorial/editorialSearch/reduxSearch/slices';
import { slice as sliceFilterContainer } from '@/modules/editorial/editorialSearchFilter/filterContainer/redux/slices';
import { slice as sliceFilterSuggester } from '@/modules/editorial/editorialSearchFilter/filterSuggester/redux/slices';
import { slice as sliceEditorialSearchResults } from '@/modules/editorial/editorialSearchResults/redux/slices';
import { slice as videoTabDestinationList } from '@/modules/editorial/editorialVideoDetails/components/Tabs/TabPublish/redux/slices';
import { slice as videoTabTargeting } from '@/modules/editorial/editorialVideoDetails/components/Tabs/TabTargeting/redux/slices';
import { slice as sliceVideoTabVersions } from '@/modules/editorial/editorialVideoDetails/components/Tabs/TabVersions/redux/slices';
import { slice as sliceEditorialVideoDetails } from '@/modules/editorial/editorialVideoDetails/redux/slices';
import { slice as slicePlaylistEdit } from '@/modules/editorial/RightSideBar/TabPlaylist/Edit/redux/slices';
import { slice as slicePlaylists } from '@/modules/editorial/RightSideBar/TabPlaylist/redux/slices';
import { slice as sliceWatchChannelEdit } from '@/modules/editorial/RightSideBar/TabWatch/ChannelEdit/redux/slices';
import { slice as sliceWatchEdit } from '@/modules/editorial/RightSideBar/TabWatch/Edit/redux/slices';
import { slice as sliceWatches } from '@/modules/editorial/RightSideBar/TabWatch/Watches/redux/slices';
import { slice as sliceShareAndAccess } from '@/modules/editorial/shareAndAccess/redux/slices';
import { slice as sliceTagEditor } from '@/modules/editorial/TagEditor/redux/slices';
import { slice as sliceEntities } from '@/modules/entities/Entities/redux/slices';
import { slice as sliceFeedEditor } from '@/modules/feeds/Editor/redux/slices';
import { slice as sliceSelfServeFeedsList } from '@/modules/feeds/SelfServeList/redux/slices';
import { slice as sliceFormEditor } from '@/modules/forms/editor/redux/slices';
import { slice as sliceForms } from '@/modules/forms/forms/redux/slices';
import { slice as sliceFormTemplateEditor } from '@/modules/forms/templateEditor/redux/slices';
import { slice as sliceFormTemplates } from '@/modules/forms/templates/redux/slices';
import { slice as hostedWatches } from '@/modules/hostedWatch/Watches/redux/slices';
import { slice as sliceHubEditor } from '@/modules/hubs/Editor/redux/slices';
import { slice as sliceHubs } from '@/modules/hubs/List/redux/slices';
import { slice as sliceInvitations } from '@/modules/invitations/List/redux/slices';
import { slice as layoutSlice } from '@/modules/layout/redux/slices';
import { slice as sliceLiveEvent } from '@/modules/liveEvents/liveEvent/redux/slices';
import { slice as sliceLiveEventsList } from '@/modules/liveEvents/LiveEventsList/redux/slices';
import { slice as sliceAccount } from '@/modules/marketplace/account/redux/slices';
import { slice as sliceAccounts } from '@/modules/marketplace/accounts/redux/slices';
import { slice as sliceMarketplaceDashboard } from '@/modules/marketplace/dashboard/redux/slices';
import { slice as sliceHbConnectors } from '@/modules/marketplace/hbConnectors/redux/slices';
import { slice as sliceMarketplaceKeyLists } from '@/modules/marketplace/keyLists/redux/slices';
import { slice as sliceNotifications } from '@/modules/notifications/redux/slices';
import { slice as sliceOnlineHelpEditor } from '@/modules/onlineHelp/Editor/redux/slices';
import { slice as sliceOnlineHelp } from '@/modules/onlineHelp/List/redux/slices';
import { slice as slicePermisssions } from '@/modules/permissions/redux/slices';
import { slice as slicePlayerEditor } from '@/modules/players/Editor/redux/slices';
import { slice as slicePlayer } from '@/modules/players/Players/redux/slices';
import { slice as sliceDestinationNameSpace } from '@/modules/publishing/Destination/redux/slices';
import { slice as sliceDestinationList } from '@/modules/publishing/DestinationList/redux/slices';
import { slice as sliceRolesPermissionsEditor } from '@/modules/rolesPermissions/Editor/redux/slices';
import { slice as sliceRolesPermissions } from '@/modules/rolesPermissions/List/redux/slices';
import { slice as sliceSsoEditor } from '@/modules/sso/Editor/redux/slices';
import { slice as sliceSsoList } from '@/modules/sso/List/redux/slices';
import { slice as sliceUploaderNew } from '@/modules/uploaderNew/redux/slices';
import { slice as sliceUserRulesSettings } from '@/modules/userRulesSettings/redux/slices';
import { slice as sliceUsersEditor } from '@/modules/users/Editor/redux/slices';
import { slice as sliceUsers } from '@/modules/users/List/redux/slices';
import { slice as sliceXRayCampaignsEditor } from '@/modules/xRay/campaigns/Editor/redux/slices';
import { slice as sliceXRayCampaigns } from '@/modules/xRay/campaigns/List/redux/slices';
import { slice as sliceXRayCreativesEditor } from '@/modules/xRay/creatives/Editor/redux/slices';
import { slice as sliceXRayCreatives } from '@/modules/xRay/creatives/List/redux/slices';
import { slice as sliceXRayLineEditor } from '@/modules/xRay/lineItems/Editor/redux/slices';
import { slice as sliceXRayLineItems } from '@/modules/xRay/lineItems/List/redux/slices';

const appReducer = combineReducers({
  // modules/@common
  [sliceCcFiles.name]: sliceCcFiles.reducer,
  [sliceGql.name]: sliceGql.reducer,
  [sliceInit.name]: sliceInit.reducer,
  [sliceLocation.name]: sliceLocation.reducer,
  [sliceMonitoring.name]: sliceMonitoring.reducer,
  [sliceRequest.name]: sliceRequest.reducer,
  [sliceToken.name]: sliceToken.reducer,
  [sliceTrimVideo.name]: sliceTrimVideo.reducer,
  [sliceUser.name]: sliceUser.reducer,

  [sliceAccount.name]: sliceAccount.reducer,
  [sliceAccounts.name]: sliceAccounts.reducer,
  [sliceMarketplaceDashboard.name]: sliceMarketplaceDashboard.reducer,
  [sliceMarketplaceKeyLists.name]: sliceMarketplaceKeyLists.reducer,
  [sliceDetailsNameSpace.name]: sliceDetailsNameSpace.reducer,
  [sliceNotify.name]: sliceNotify.reducer,
  [slicePlaylists.name]: slicePlaylists.reducer,
  [slicePlaylistEdit.name]: slicePlaylistEdit.reducer,
  [sliceWatches.name]: sliceWatches.reducer,
  [sliceWatchEdit.name]: sliceWatchEdit.reducer,
  [sliceWatchChannelEdit.name]: sliceWatchChannelEdit.reducer,
  [hostedWatches.name]: hostedWatches.reducer,
  [sliceDestinationList.name]: sliceDestinationList.reducer,
  [sliceDestinationNameSpace.name]: sliceDestinationNameSpace.reducer,
  [sliceLiveEvent.name]: sliceLiveEvent.reducer,
  [sliceLiveEventsList.name]: sliceLiveEventsList.reducer,
  [sliceConfiguration.name]: sliceConfiguration.reducer,
  [sliceLogin.name]: sliceLogin.reducer,
  [sliceShareAndAccess.name]: sliceShareAndAccess.reducer,
  [sliceEditorialSearch.name]: sliceEditorialSearch.reducer,
  [sliceFilterContainer.name]: sliceFilterContainer.reducer,
  [sliceFilterSuggester.name]: sliceFilterSuggester.reducer,
  [sliceEditorialSearchResults.name]: sliceEditorialSearchResults.reducer,
  [sliceEditorialVideoDetails.name]: sliceEditorialVideoDetails.reducer,
  [layoutSlice.name]: layoutSlice.reducer,

  [sliceFormEditor.name]: sliceFormEditor.reducer,
  [sliceForms.name]: sliceForms.reducer,

  [sliceAnalyticsVideoContentPerformance.name]: sliceAnalyticsVideoContentPerformance.reducer,
  [sliceAnalyticsLiveDashboard.name]: sliceAnalyticsLiveDashboard.reducer,
  [sliceAnalyticsMonetization.name]: sliceAnalyticsMonetization.reducer,
  [sliceAnalyticsCustomReports.name]: sliceAnalyticsCustomReports.reducer,
  [sliceAnalyticsRevenueOverview.name]: sliceAnalyticsRevenueOverview.reducer,

  [sliceUserRulesSettings.name]: sliceUserRulesSettings.reducer,

  [sliceFormTemplates.name]: sliceFormTemplates.reducer,
  [sliceFormTemplateEditor.name]: sliceFormTemplateEditor.reducer,

  [sliceAnalyticsGeneral.name]: sliceAnalyticsGeneral.reducer,

  [sliceAuthLayout.name]: sliceAuthLayout.reducer,
  [sliceAuthCreateResetPassword.name]: sliceAuthCreateResetPassword.reducer,
  [sliceAuthGuestActivation.name]: sliceAuthGuestActivation.reducer,

  [sliceUploaderNew.name]: sliceUploaderNew.reducer,

  [sliceTagEditor.name]: sliceTagEditor.reducer,

  [videoTabTargeting.name]: videoTabTargeting.reducer,

  [sliceHbConnectors.name]: sliceHbConnectors.reducer,

  [sliceEditorialPlayerPreview.name]: sliceEditorialPlayerPreview.reducer,

  [videoTabDestinationList.name]: videoTabDestinationList.reducer,

  [sliceHubs.name]: sliceHubs.reducer,
  [sliceHubEditor.name]: sliceHubEditor.reducer,

  [sliceInvitations.name]: sliceInvitations.reducer,

  [sliceCustomDashboards.name]: sliceCustomDashboards.reducer,
  [sliceCustomDashboardsEditor.name]: sliceCustomDashboardsEditor.reducer,

  [sliceUsers.name]: sliceUsers.reducer,
  [sliceUsersEditor.name]: sliceUsersEditor.reducer,

  [sliceEntities.name]: sliceEntities.reducer,

  [slicePlayer.name]: slicePlayer.reducer,
  [slicePlayerEditor.name]: slicePlayerEditor.reducer,

  [sliceAiWorkbench.name]: sliceAiWorkbench.reducer,
  [sliceAiWorkbenchChapters.name]: sliceAiWorkbenchChapters.reducer,
  [sliceAiWorkbenchHighlights.name]: sliceAiWorkbenchHighlights.reducer,
  [sliceAiWorkbenchCreateVideo.name]: sliceAiWorkbenchCreateVideo.reducer,
  [sliceAiWorkbenchSlides.name]: sliceAiWorkbenchSlides.reducer,
  [sliceAiWorkbenchTranslations.name]: sliceAiWorkbenchTranslations.reducer,
  [sliceAiWorkbenchDescription.name]: sliceAiWorkbenchDescription.reducer,
  [sliceAiWorkbenchTagLog.name]: sliceAiWorkbenchTagLog.reducer,
  [sliceAiWorkbenchThumbnail.name]: sliceAiWorkbenchThumbnail.reducer,

  [sliceVideoTabVersions.name]: sliceVideoTabVersions.reducer,
  [sliceBulkActions.name]: sliceBulkActions.reducer,
  [sliceBulkShareActions.name]: sliceBulkShareActions.reducer,

  [sliceAdvertisers.name]: sliceAdvertisers.reducer,
  [sliceAdvertiserEditor.name]: sliceAdvertiserEditor.reducer,

  [sliceNotifications.name]: sliceNotifications.reducer,

  [sliceAdServersList.name]: sliceAdServersList.reducer,
  [sliceAdServersEditor.name]: sliceAdServersEditor.reducer,

  [sliceContentOwnersList.name]: sliceContentOwnersList.reducer,
  [sliceContentOwnersEditor.name]: sliceContentOwnersEditor.reducer,

  [slicePermisssions.name]: slicePermisssions.reducer,

  [sliceOnlineHelp.name]: sliceOnlineHelp.reducer,
  [sliceOnlineHelpEditor.name]: sliceOnlineHelpEditor.reducer,

  [sliceAccountsList.name]: sliceAccountsList.reducer,
  [sliceAccountsEditor.name]: sliceAccountsEditor.reducer,

  [sliceXRayCampaigns.name]: sliceXRayCampaigns.reducer,
  [sliceXRayCampaignsEditor.name]: sliceXRayCampaignsEditor.reducer,

  [sliceXRayCreatives.name]: sliceXRayCreatives.reducer,
  [sliceXRayCreativesEditor.name]: sliceXRayCreativesEditor.reducer,

  [sliceXRayLineItems.name]: sliceXRayLineItems.reducer,
  [sliceXRayLineEditor.name]: sliceXRayLineEditor.reducer,

  [sliceRolesPermissions.name]: sliceRolesPermissions.reducer,
  [sliceRolesPermissionsEditor.name]: sliceRolesPermissionsEditor.reducer,

  [sliceSsoList.name]: sliceSsoList.reducer,
  [sliceSsoEditor.name]: sliceSsoEditor.reducer,

  [sliceSelfServeFeedsList.name]: sliceSelfServeFeedsList.reducer,
  [sliceFeedEditor.name]: sliceFeedEditor.reducer,
});

type RootState = ReturnType<typeof appReducer>;

type Action = {
  type: string;
  payload?: unknown;
};

export default (state: RootState | undefined, action: Action): RootState =>
  appReducer(action.type === 'RESET_STORE' ? undefined : state, action);
