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

const initialState = {
  selectedVideo: {},
  monitoringJob: null,
  currentVideoTime: 0,
  updateVideo: null,
  evergreen: false,
  dialogVisible: false,
  setThumbnailUrl: null,
  uploadThumbnail: {},
  getPlayerEmbedCode: null,
  keywords: [],
  isLoadingKeywords: false,
  newKeyword: null,
  getTaxonomyKeywords: null,
  createTaxonomyKeyword: null,
  showNotification: '',
  deleteVideo: null,
  speechToTextModel: 'DEEPGRAM_ANYCLIP',
  speechToTextModels: [],
  downloadTags: '',
  getOwnersOptions: null,
  ownersOptions: null,
  advertiserOptions: null,
  tabIndex: 0,
};

export const slice = createSlice({
  name: '@@editorialVideoDetails/EDITORIAL_VIDEO_DETAILS',
  initialState,
  reducers: {
    selectedVideoAction: (state, action) => {
      state.selectedVideo = action.payload || initialState.selectedVideo;
    },
    currentVideoTimeAction: (state, action) => {
      state.currentVideoTime = action.payload || initialState.currentVideoTime;
    },
    monitoringJobAction: (state, action) => {
      state.monitoringJob = action.payload || initialState.monitoringJob;
    },
    updateVideoAction: (state, action) => {
      state.updateVideo = action.payload || initialState.updateVideo;
    },
    evergreenAction: (state, action) => {
      state.evergreen = action.payload || initialState.evergreen;
    },
    dialogVisibleAction: (state, action) => {
      state.dialogVisible = action.payload || initialState.dialogVisible;
    },
    getPlayerEmbedCodeAction: (state, action) => {
      state.getPlayerEmbedCode = action.payload || initialState.getPlayerEmbedCode;
    },
    keywordsAction: (state, action) => {
      state.keywords = action.payload || initialState.keywords;
    },
    isLoadingKeywordsAction: (state, action) => {
      state.isLoadingKeywords = action.payload || initialState.isLoadingKeywords;
    },
    newKeywordAction: (state, action) => {
      state.newKeyword = action.payload || initialState.newKeyword;
    },
    getTaxonomyKeywordsAction: (state, action) => {
      state.getTaxonomyKeywords = action.payload || initialState.getTaxonomyKeywords;
    },
    createTaxonomyKeywordAction: (state, action) => {
      state.createTaxonomyKeyword = action.payload || initialState.createTaxonomyKeyword;
    },
    showNotificationAction: (state, action) => {
      state.showNotification = action.payload || initialState.showNotification;
    },
    deleteVideoAction: (state, action) => {
      state.deleteVideo = action.payload || initialState.deleteVideo;
    },
    speechToTextModelAction: (state, action) => {
      state.speechToTextModel = action.payload || initialState.speechToTextModel;
    },
    speechToTextModelsAction: (state, action) => {
      state.speechToTextModels = action.payload || initialState.speechToTextModels;
    },
    getOwnersOptionsAction: (state, action) => {
      state.getOwnersOptions = action.payload || initialState.getOwnersOptions;
    },
    ownersOptionsAction: (state, action) => {
      state.ownersOptions = action.payload || initialState.ownersOptions;
    },
    setTabIndexAction: (state, action) => {
      state.tabIndex = action.payload;
    },
    setAdvertiserOptionsAction: (state, action) => {
      state.advertiserOptions = action.payload || initialState.advertiserOptions;
    },
    reloadSelectedVideoAction: (state) => state,
    getSpeechToTextModelsAction: (state) => state,
    updateVideoTagsAction: (state) => state,
    getAdvertiserOptionsAction: (state) => state,
    clearAction: (state) => {
      Object.keys(initialState).forEach((key) => {
        if (key !== 'tabIndex') {
          state[key] = initialState[key];
        }
      });
    },
  },
});

export const {
  selectedVideoAction,
  currentVideoTimeAction,
  monitoringJobAction,
  updateVideoAction,
  evergreenAction,
  dialogVisibleAction,
  getPlayerEmbedCodeAction,
  keywordsAction,
  isLoadingKeywordsAction,
  newKeywordAction,
  getTaxonomyKeywordsAction,
  createTaxonomyKeywordAction,
  showNotificationAction,
  deleteVideoAction,
  speechToTextModelAction,
  speechToTextModelsAction,
  getOwnersOptionsAction,
  ownersOptionsAction,
  setTabIndexAction,
  reloadSelectedVideoAction,
  getSpeechToTextModelsAction,
  updateVideoTagsAction,
  clearAction,
  getAdvertiserOptionsAction,
  setAdvertiserOptionsAction,
} = slice.actions;
