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

const initialState = {
  ccSegments: null,
  highlights: [],
  published: false,
  draft: false,
  processing: false,
  processingPercentage: null,
  currentProcessingJobType: null,

  isLoading: false,
  shouldOpenGenerateByAiConfirm: false,
  isDirty: false,

  isGeneratingAvailable: false,
  causes: [],

  videos: [],
  lastCreatedVideoId: null,
};

export const slice = createSlice({
  name: '@@AIWORKBENCH/HIGHLIGHTS',
  initialState,
  reducers: {
    setAction: (state, action) => {
      Object.keys(action.payload).forEach((key) => {
        state[key] = action.payload[key];
      });
    },
    getCcSegmentsAction: (state) => state,
    getHighlightsAction: (state) => state,
    setHighlightsAction: (state) => state,
    publishUnpublishAction: (state) => state,
    toggleConfirmForGenerateByAiConfirmAction: (state, action) => {
      state.shouldOpenGenerateByAiConfirm = action.payload;
    },
    generateByAiAction: (state) => state,
    unmountAction: (state) => {
      state.isDirty = false;
      state.highlights = [];
      state.lastCreatedVideoId = null;
    },
    createVideoAction: (state) => state,
    getListOfCreatedVideo: (state) => state,
  },
});

export const {
  setAction,
  getCcSegmentsAction,
  getHighlightsAction,
  setHighlightsAction,
  publishUnpublishAction,
  toggleConfirmForGenerateByAiConfirmAction,
  generateByAiAction,
  unmountAction,
  getListOfCreatedVideo,
  createVideoAction,
} = slice.actions;
