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

const initialState = {
  description: null,
  descriptions: null,
  published: false,
  draft: false,
  processing: false,

  processingPercentage: null,

  isLoading: false,

  shouldOpenGenerateByAiConfirm: false,

  isGeneratingAvailable: false,
  causes: [],

  isDirty: false,
};

export const slice = createSlice({
  name: '@@AIWORKBENCH/DESCRIPTION',
  initialState,
  reducers: {
    getDescriptionAction: (state) => state,
    setDescriptionAction: (state) => state,
    generateByAiAction: (state) => state,
    publishUnpublishAction: (state) => state,
    setAction: (state, action) => {
      Object.keys(action.payload).forEach((key) => {
        state[key] = action.payload[key];
      });
    },
    toggleConfirmForGenerateByAiConfirmAction: (state, action) => {
      state.shouldOpenGenerateByAiConfirm = action.payload;
    },
    unmountAction: (state) => {
      state.description = null;
      state.descriptionOptions = null;
      state.isDirty = false;
    },
    updateDescriptionInVideoListOrDetailAction: (state) => state,
  },
});

export const {
  getDescriptionAction,
  setDescriptionAction,
  generateByAiAction,
  publishUnpublishAction,
  setAction,
  toggleConfirmForGenerateByAiConfirmAction,
  unmountAction,
  updateDescriptionInVideoListOrDetailAction,
} = slice.actions;
