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

const initialState = {
  slides: null,
  published: false,
  draft: false,
  processing: false,
  processingPercentage: null,
  download: false,

  isLoading: false,
  formId: null,
  shouldOpenGenerateByAiConfirm: false,
  pdfFile: '',
  isPdfFileReadyToDownload: false,
  isDirty: false,

  isGeneratingAvailable: false,
  causes: [],
};

export const slice = createSlice({
  name: '@@AIWORKBENCH/SLIDES',
  initialState,
  reducers: {
    setAction: (state, action) => {
      Object.keys(action.payload).forEach((key) => {
        state[key] = action.payload[key];
      });
    },
    getSlidesAction: (state) => state,
    setSlidesAction: (state) => state,
    toggleConfirmForGenerateByAiConfirmAction: (state, action) => {
      state.shouldOpenGenerateByAiConfirm = action.payload;
    },
    generateByAiAction: (state) => state,
    uploadAction: (state) => state,
    setStateAction: (state) => state,
    runPdfMonitoringAction: (state) => state,
    unmountAction: (state) => {
      state.isDirty = false;
      state.formId = null;
      state.slides = null;
    },
  },
});

export const {
  setAction,
  getSlidesAction,
  setSlidesAction,
  toggleConfirmForGenerateByAiConfirmAction,
  generateByAiAction,
  uploadAction,
  setStateAction,
  runPdfMonitoringAction,
  unmountAction,
} = slice.actions;
