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

const initialState = {
  destinations: [],
  totalDestinations: 0,

  publishers: [],

  search: '',
  page: 1,
  pageSize: 10,
  sortBy: 'id',
  sortOrder: 'DESC',
  platform: null,
  status: null,
  publisherId: null,

  publishEntries: [],

  viewabilityConfig: [],
};

export const slice = createSlice({
  name: '@@videoTabDestinationList',
  initialState,
  reducers: {
    getDestinationsAction: (state, action) => {
      Object.keys(action.payload).forEach((key) => {
        state[key] = action.payload[key];
      });
    },
    setDestinationsAction: (state, action) => {
      state.destinations = action.payload;
    },
    setTotalDestinationsAction: (state, action) => {
      state.totalDestinations = action.payload;
    },
    setPublishersAction: (state, action) => {
      state.publishers = action.payload;
    },
    setPublishEntriesAction: (state, action) => {
      state.publishEntries = action.payload;
    },
    setFilterParamAction: (state, action) => {
      Object.keys(action.payload).forEach((key) => {
        state[key] = action.payload[key];
      });
    },
    clearFilterParamsAction: (state) => {
      Object.keys(initialState).forEach((key) => {
        if (key !== 'viewabilityConfig') {
          state[key] = initialState[key];
        }
      });
    },
    setViewabilityConfigAction: (state, action) => {
      state.viewabilityConfig = action.payload;
    },
    addPublishEntriesAction: (state) => state,
    getPublishersAction: (state) => state,
    getPublishEntriesAction: (state) => state,
    deletePublishEntriesAction: (state) => state,
    updatePublishEntryAction: (state) => state,
    getViewabilityConfigAction: (state) => state,
  },
});

export const {
  getDestinationsAction,
  setDestinationsAction,
  setTotalDestinationsAction,
  setPublishersAction,
  setPublishEntriesAction,
  setFilterParamAction,
  clearFilterParamsAction,
  setViewabilityConfigAction,
  addPublishEntriesAction,
  getPublishersAction,
  getPublishEntriesAction,
  deletePublishEntriesAction,
  updatePublishEntryAction,
  getViewabilityConfigAction,
} = slice.actions;
