import { createTypedReducerWithImmer } from "@insite/client-framework/Common/CreateTypedReducer";
import { ProcessFileResult } from "@insite/client-framework/Store/Components/VmiCountsImportModal/Handlers/ProcessFile";
import VmiCountsImportModalState from "@insite/client-framework/Store/Components/VmiCountsImportModal/VmiCountsImportModalState";
import { Draft } from "immer";

const initialState: VmiCountsImportModalState = {
    parsedItems: [],
    isBadFile: false,
    isUploading: false,
    uploadLimitExceeded: false,
    modalIsOpen: false,
};

const reducer = {
    "Components/VmiCountsImportModal/BeginProcessFile": (draft: Draft<VmiCountsImportModalState>) => {},
    "Components/VmiCountsImportModal/CompleteProcessFile": (
        draft: Draft<VmiCountsImportModalState>,
        action: { result: ProcessFileResult },
    ) => {
        draft.parsedItems = action.result.parsedItems;
        draft.uploadLimitExceeded = action.result.uploadLimitExceeded;
        draft.isBadFile = action.result.isBadFile;
        draft.isUploading = action.result.isUploading;
    },
    "Components/VmiCountsImportModal/SetIsBadFile": (
        draft: Draft<VmiCountsImportModalState>,
        action: { parameter: { isBadFile: boolean } },
    ) => {
        draft.isBadFile = action.parameter.isBadFile;
    },
    "Components/VmiCountsImportModal/SetIsUploading": (
        draft: Draft<VmiCountsImportModalState>,
        action: { parameter: { isUploading: boolean } },
    ) => {
        draft.isUploading = action.parameter.isUploading;
    },
    "Components/VmiCountsImportModal/SetUploadLimitExceeded": (
        draft: Draft<VmiCountsImportModalState>,
        action: { parameter: { uploadLimitExceeded: boolean } },
    ) => {
        draft.uploadLimitExceeded = action.parameter.uploadLimitExceeded;
    },
    "Components/VmiCountsImportModal/SetModalIsOpen": (
        draft: Draft<VmiCountsImportModalState>,
        action: { isOpen: boolean },
    ) => {
        draft.modalIsOpen = action.isOpen;
    },
};

export default createTypedReducerWithImmer(initialState, reducer);
