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

import { AD_PLAYBACK_STATUS_OFF, BUDGET_CONTROL_STATUS_OFF, TARGETING_STATUS_OFF } from '../../constants';

const initialState = {
  data: null,
  countryOptions: [],
  targetingStatus: TARGETING_STATUS_OFF,
  adPlaybackStatus: AD_PLAYBACK_STATUS_OFF,
  budgetControlStatus: BUDGET_CONTROL_STATUS_OFF,
  lastCreatedIdForOpenEdit: null,
  isLoading: true,
  playersWithDisabledTargeting: null,
};

export const slice = createSlice({
  name: '@@VIDEO_TAB_TARGETING',
  initialState,
  reducers: {
    setStateAction: (state, action) => {
      Object.keys(action.payload).forEach((key) => {
        state[key] = action.payload[key];
      });
    },
    clearAction: () => initialState,
    getTargetingAction: (state) => state,
    createTargetingAction: (state) => state,
    updateTargetingAction: (state) => state,
    removeTargetingAction: (state) => state,
    runActionTargetingAction: (state) => state,
    getTargetingStatusesAction: (state) => state,
    changeTargetingStatusesAction: (state) => state,
    getPlayersWithDisabledTargeting: (state) => state,
  },
});

export const {
  setStateAction,
  clearAction,
  getTargetingAction,
  createTargetingAction,
  updateTargetingAction,
  removeTargetingAction,
  runActionTargetingAction,
  getTargetingStatusesAction,
  changeTargetingStatusesAction,
  getPlayersWithDisabledTargeting,
} = slice.actions;
