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

const initialState = {
  isLoading: true,
  providers: [],
  awsRecognitionModels: {
    providerName: 'AMAZON',
    formList: [],
    tempForm: null,
  },
  clarifaiModels: {
    providerName: 'CLARIFAI',
    formList: [],
    tempForm: null,
  },
  googleModels: {
    providerName: 'GOOGLE',
    formList: [],
    tempForm: null,
  },
  weavoModels: {
    providerName: 'WEAVO',
    formList: [],
    tempForm: null,
  },
  dictionaryBrandSafetyCategories: [],
  dictionaryIabClassificationCategories: [],
  notifications: [],
  dictionaryBrandSafetySpeech: [],
  dictionaryBrandSafetyText: [],
  dictionaryBlacklistFile: {},
  dictionaryMapFile: {},
  dictionaryCategorizationFile: {},
  dictionaryFilterFile: {},
  dictionaryBrandSafetyFile: {},
  htmlParsingConfigFile: {},
  classificationIabWeightsFile: {},
  classificationIabCelebritiesMapFile: {},
  classificationIabMapFile: {},
  classificationKeywordsLowerbound: 0,
  classificationKeywordsCount: 0,
  classificationIabCount: 0,
  classificationIabLowerbound: 0,
  enableIabKeywordsMergingAlgorithm: false,
  enableIabCategorizationAlgorithm: false,
};

export const slice = createSlice({
  name: '@@CONFIG_PAGE',
  initialState,
  reducers: {
    getConfigurationDataAction: (state) => state,
    updateConfigurationByPropAction: (state, action) => {
      Object.keys(action.payload).forEach((key) => {
        state[key] = action.payload[key];
      });
    },
    uploadConfigFileAction: (state) => state,
    setConfigurationDataAction: (state, action) => {
      Object.keys(action.payload).forEach((key) => {
        state[key] = action.payload[key];
      });

      state.isLoading = false;
    },
    saveConfigurationDataOnServerAction: (state) => state,
    onUpdateFormAction: (state) => state,
    onDeleteFormAction: (state) => state,
    onAddFormAction: (state) => state,
    onChangeModelFormAction: (state) => state,
    onChangeModelTempFormAction: (state) => state,
  },
});

export const {
  getConfigurationDataAction,
  updateConfigurationByPropAction,
  uploadConfigFileAction,
  setConfigurationDataAction,
  saveConfigurationDataOnServerAction,
  onUpdateFormAction,
  onDeleteFormAction,
  onAddFormAction,
  onChangeModelFormAction,
  onChangeModelTempFormAction,
} = slice.actions;
