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

const initialState = {
  logRequest: null,
  logResponse: null,
  logError: null,
  logFilteredResponse: null,

  barRequest: null,
  barResponse: null,
  barError: null,
  barFilteredResponse: null,

  videosRequest: null,

  initResponse: null,
  initError: null,
};

export const slice = createSlice({
  name: '@@COMMON/GQL',
  initialState,

  reducers: {
    clearAction: (state) => state,
    logRequestEventAction: (state) => state,
    logResponseEventAction: (state) => state,
    logErrorEventAction: (state) => state,
    logFilteredRequestEventAction: (state) => state,
    logFilteredResponseEventAction: (state) => state,
    barRequestEventAction: (state) => state,
    barResponseEventAction: (state) => state,
    barErrorEventAction: (state) => state,
    barFilteredRequestEventAction: (state) => state,
    barFilteredResponseEventAction: (state) => state,
    initRequestEventAction: (state) => state,
    initResponseEventAction: (state) => state,
    initErrorEventAction: (state) => state,
    logRequestAction: (state, action) => {
      state.logRequest = action.payload || initialState.logRequest;
    },
    logResponseAction: (state, action) => {
      state.logResponse = action.payload || initialState.logResponse;
    },
    logErrorAction: (state, action) => {
      state.logError = action.payload || initialState.logError;
    },
    logFilteredResponseAction: (state, action) => {
      state.logFilteredResponse = action.payload || initialState.logFilteredResponse;
    },
    barRequestAction: (state, action) => {
      state.barRequest = action.payload || initialState.barRequest;
    },
    barResponseAction: (state, action) => {
      state.barResponse = action.payload || initialState.barResponse;
    },
    barErrorAction: (state, action) => {
      state.barError = action.payload || initialState.barError;
    },
    barFilteredResponseAction: (state, action) => {
      state.barFilteredResponse = action.payload || initialState.barFilteredResponse;
    },
    initResponseAction: (state, action) => {
      state.initResponse = action.payload || initialState.initResponse;
    },
    initErrorAction: (state, action) => {
      state.initError = action.payload || initialState.initError;
    },
  },
});

export const {
  barErrorAction,
  barErrorEventAction,
  barFilteredRequestEventAction,
  barFilteredResponseAction,
  barFilteredResponseEventAction,
  barRequestAction,
  barRequestEventAction,
  barResponseAction,
  barResponseEventAction,
  clearAction,
  initErrorAction,
  initErrorEventAction,
  initRequestEventAction,
  initResponseAction,
  initResponseEventAction,
  logErrorAction,
  logErrorEventAction,
  logFilteredRequestEventAction,
  logFilteredResponseAction,
  logFilteredResponseEventAction,
  logRequestAction,
  logRequestEventAction,
  logResponseAction,
  logResponseEventAction,
} = slice.actions;

export default slice.reducer;
