/*
 * File: settingsSlice.ts
 * Description: Redux slice for user settings state management
 * Design & Developed by Tech4Biz Solutions
 * Copyright (c) Spurrin Innovations. All rights reserved.
 */

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

export interface UserSettings {
  notificationsEnabled: boolean;
  darkMode: boolean;
  language: string;
}

interface SettingsState {
  settings: UserSettings;
  loading: boolean;
  error: string | null;
}

const initialState: SettingsState = {
  settings: {
    notificationsEnabled: true,
    darkMode: false,
    language: 'en',
  },
  loading: false,
  error: null,
};

/**
 * settingsSlice for managing user settings
 */
const settingsSlice = createSlice({
  name: 'settings',
  initialState,
  reducers: {
    updateSettings(state, action: PayloadAction<Partial<UserSettings>>) {
      state.settings = { ...state.settings, ...action.payload };
    },
    setSettingsLoading(state, action: PayloadAction<boolean>) {
      state.loading = action.payload;
    },
    setSettingsError(state, action: PayloadAction<string | null>) {
      state.error = action.payload;
    },
  },
});

export const {
  updateSettings,
  setSettingsLoading,
  setSettingsError,
} = settingsSlice.actions;

export default settingsSlice.reducer;

/*
 * End of File: settingsSlice.ts
 * Design & Developed by Tech4Biz Solutions
 * Copyright (c) Spurrin Innovations. All rights reserved.
 */ 