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

const initialState = {
  liveEvents: [],
  totalEvents: 0,

  selectedEvents: [],

  players: null,
  publishers: [],

  embedCode: '',

  search: '',
  page: 1,
  pageSize: 15,
  sortBy: 'updatedAt',
  sortOrder: 'DESC',
  eventFilter: null,
  status: 'active',
  publisherId: null,
  playerId: null,
};

export const slice = createSlice({
  name: '@@LIVE_EVENTS/LIVE_EVENTS_LIST',
  initialState,

  reducers: {
    archiveLiveEventsAction: (state) => state,
    getPlayersAction: (state) => state,
    getPublishersAction: (state) => state,
    getEmbedCodeAction: (state) => state,
    getLiveEventsAction: (state, action) => {
      Object.keys(action.payload ?? {}).forEach((key) => {
        state[key] = action.payload[key];
      });
      state.selectedEvents = [];
    },
    setLiveEventsAction: (state, action) => {
      state.liveEvents = action.payload;
    },
    setTotalEventsAction: (state, action) => {
      state.totalEvents = action.payload;
    },
    setSelectedEventsAction: (state, action) => {
      state.selectedEvents = action.payload;
    },
    setPlayersAction: (state, action) => {
      state.players = action.payload;
    },
    setPublishersAction: (state, action) => {
      state.publishers = action.payload;
    },
    setEmbedCodeAction: (state, action) => {
      state.embedCode = action.payload;
    },
  },
});

export const {
  archiveLiveEventsAction,
  getEmbedCodeAction,
  getLiveEventsAction,
  getPlayersAction,
  getPublishersAction,
  setEmbedCodeAction,
  setLiveEventsAction,
  setPlayersAction,
  setPublishersAction,
  setSelectedEventsAction,
  setTotalEventsAction,
} = slice.actions;

export default slice.reducer;
