import { configureStore } from "@reduxjs/toolkit";

// All API files
import { sendOtp } from "./api/SendOTP";
import { sendEmailOtp } from "./api/ResendEmailOTP";
import { getAllPostReel }  from './api/GetAllPostReel'
import { getAllStory } from './api/GetStoryByUser'
import {getAllUsers} from './api/AllUsersList'
import {getUserProfileDetails} from './api/GetUserProfileDetails'
import { getMyAllPost } from './api/GetMyAllPost'
import {getMyAllReels} from './api/GetMyAllReels'
import {getMyAllTagPost} from './api/GetAllMyTagPost'
import {getMyStoryHighlight} from './api/GetMyStoryHighlight'
import {getMyAllFollowing} from './api/GetMyFollowing'
import {getMyAllFollowers} from './api/GetMyFollowers'
import {getBlockedUserList} from './api/BlockedUserList'
import {getBookmarkPostList} from './api/BookmarkPostList'
import { userChatList } from "./api/UserChatList";
import {getAllOnlineUser} from './api/OnlineUserList'
import { getPolicy } from "./api/GetPrivacyPolicyTermsConditions";
import {deleteAccount} from './api/DeleteAccount'
import { getHashtagList } from "./api/GetHashtagList";
import { getUserNotification } from './api/UserNotificationList'
import { getUserNotificationCount } from "./api/UserNotificationReadCount";
import { getAllHashtag } from './api/getTrendingHashtag'
import { getAllLanguage } from './api/useFetchLanguageList';
import { languageTextApi } from "./api/useFetchDefaultLanguageTextList";
import  tagUserSlice from './Slice/tagUsersSlice'
import reportReducer from "./Slice/ReportSlice";

// All Slice Files
import mobileSlice from './Slice/MobileNumber'
import emailSlice from './Slice/Email'
import profileSlice from "./Slice/UserProfileImage";
import setFirstPostImage from "./Slice/SecondUserFirstPostImage";
import setFirstReelThumbnail from "./Slice/SecondUserFirstReelThumbnail";
import userIdSlice from './Slice/SetUserIdForChatOpen'
import myUserSlice from './Slice/storeMyUserId'
import usernameProfileSlice from './Slice/UsernameProfile'
import chatSlice from './Slice/chatSlice'
import messageSlice from './Slice/messageSlice'
import chatUserSlice from './Slice/chatUserSlice'
import SendMessageSlice from './Slice/SendMessageSlice'
import firstUserSlice from "./Slice/FirstUserChatSlice";
import fileSlice from './Slice/FileSelectSlice';
import newUserSlice from './Slice/NewUserChatSlice';
import modalSlice from './Slice/modalSlice';
import currentStorySlice from './Slice/currentStorySlice'
import taggedPostSlice from './Slice/TaggedPeopleListPost'
import ReelIdSlice from './Slice/ReelIdSlice'
import PostIdSlice from './Slice/PostIdSlice'
import SelectedReelIdSlice from './Slice/selectedReelIdSlice'
import SelectedPostIdSlice from './Slice/selectedPostIdSlice'
import UserIdSlice from './Slice/SecondUserIdSlice'
import hashtagIdSlice from './Slice/hashtagIdSlice'
import hideOptionSlice from './Slice/hideOptionSlice'
import notificationSlice from './Slice/notificationMessage'
import LanguageTextListSlice from './Slice/LanguageTextListSlice'
import followStatsSlice from './Slice/MyFollowingSlice'
import AddPostSlice from './Slice/AddPostSlice'
import viewedUserReducer from './Slice/ViewedUserSlice';
import viewOnlyReducer from './Slice/ViewOnlySlice';
// ✅ Fix the Dispatch type export
export const store = configureStore({
    reducer: {
        // All slice
        mobile: mobileSlice,
        email: emailSlice,
        profile: profileSlice,
        seconduserfirstpost: setFirstPostImage,
        seconduserreelpost: setFirstReelThumbnail,
        userid: userIdSlice,
        myUserid: myUserSlice,
        usernameProfile: usernameProfileSlice,
        chat: chatSlice,
        message: messageSlice,
        chatUser: chatUserSlice,
        sendMessage: SendMessageSlice,
        firstUser: firstUserSlice,
        file: fileSlice,
        newUserId: newUserSlice,
        modals: modalSlice,
        currentStory: currentStorySlice,
        taggedPost: taggedPostSlice,
        ReelId: ReelIdSlice,
        PostId: PostIdSlice,
        SelectedReelId: SelectedReelIdSlice,
        SelectedPostId: SelectedPostIdSlice,
        UserId: UserIdSlice,
        HashtagId: hashtagIdSlice,
        hideOption: hideOptionSlice,
        count: notificationSlice,
        language: LanguageTextListSlice,
        following: followStatsSlice,
        tagUsers: tagUserSlice,
        addPost: AddPostSlice, // ✅ Correctly added
        viewedUser: viewedUserReducer,
        report: reportReducer,
        viewOnly: viewOnlyReducer,
        

        // All API methods
        [sendOtp.reducerPath]: sendOtp.reducer,
        [sendEmailOtp.reducerPath]: sendEmailOtp.reducer,
        [getAllPostReel.reducerPath]: getAllPostReel.reducer,
        [getAllStory.reducerPath]: getAllStory.reducer,
        [getAllUsers.reducerPath]: getAllUsers.reducer,
        [getUserProfileDetails.reducerPath]: getUserProfileDetails.reducer,
        [getMyAllPost.reducerPath]: getMyAllPost.reducer,
        [getMyAllReels.reducerPath]: getMyAllReels.reducer,
        [getMyAllTagPost.reducerPath]: getMyAllTagPost.reducer,
        [getMyStoryHighlight.reducerPath]: getMyStoryHighlight.reducer,
        [getMyAllFollowing.reducerPath]: getMyAllFollowing.reducer,
        [getMyAllFollowers.reducerPath]: getMyAllFollowers.reducer,
        [getBlockedUserList.reducerPath]: getBlockedUserList.reducer,
        [getBookmarkPostList.reducerPath]: getBookmarkPostList.reducer,
        [userChatList.reducerPath]: userChatList.reducer,
        [getAllOnlineUser.reducerPath]: getAllOnlineUser.reducer,
        [getPolicy.reducerPath]: getPolicy.reducer,
        [deleteAccount.reducerPath]: deleteAccount.reducer,
        [getHashtagList.reducerPath]: getHashtagList.reducer,
        [getUserNotification.reducerPath]: getUserNotification.reducer,
        [getUserNotificationCount.reducerPath]: getUserNotificationCount.reducer,
        [getAllHashtag.reducerPath]: getAllHashtag.reducer,
        [getAllLanguage.reducerPath]: getAllLanguage.reducer,
        [languageTextApi.reducerPath]: languageTextApi.reducer,
    },

    middleware: (getDefaultMiddleware) =>
        getDefaultMiddleware({
            serializableCheck: false
        })
        .concat(sendOtp.middleware)
        .concat(sendEmailOtp.middleware)
        .concat(getAllPostReel.middleware)
        .concat(getAllStory.middleware)
        .concat(getAllUsers.middleware)
        .concat(getUserProfileDetails.middleware)
        .concat(getMyAllPost.middleware)
        .concat(getMyAllReels.middleware)
        .concat(getMyAllTagPost.middleware)
        .concat(getMyStoryHighlight.middleware)
        .concat(getMyAllFollowing.middleware)
        .concat(getMyAllFollowers.middleware)
        .concat(getBlockedUserList.middleware)
        .concat(getBookmarkPostList.middleware)
        .concat(userChatList.middleware)
        .concat(getAllOnlineUser.middleware)
        .concat(getPolicy.middleware)
        .concat(deleteAccount.middleware)
        .concat(getHashtagList.middleware)
        .concat(getUserNotification.middleware)
        .concat(getUserNotificationCount.middleware)
        .concat(getAllHashtag.middleware)
        .concat(getAllLanguage.middleware)
        .concat(languageTextApi.middleware)
        
})

export type RootState = ReturnType<typeof store.getState>;
export type AppDispatch = typeof store.dispatch;