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

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

// Sample user profile type
export interface UserProfile {
  id: string;
  name: string;
  email: string;
  avatar?: string;
  role?: string;
  location?: string;
}

// Profile state type
interface ProfileState {
  userProfile: UserProfile | null;
  loading: boolean;
  error: string | null;
}

const initialState: ProfileState = {
  userProfile: {
    id:'1',
    name:'laxman h',
    email:'laxman.halaki@tech4biz.org',
    avatar:'',
    role:'doctor'

  },
  loading: false,
  error: null,
};

/**
 * Profile slice for managing user profile state
 */
const profileSlice = createSlice({
  name: 'profile',
  initialState,
  reducers: {
    fetchProfileStart(state) {
      state.loading = true;
      state.error = null;
    },
    fetchProfileSuccess(state, action: PayloadAction<UserProfile>) {
      state.userProfile = action.payload;
      state.loading = false;
    },
    fetchProfileFailure(state, action: PayloadAction<string>) {
      state.loading = false;
      state.error = action.payload;
    },
    updateProfile(state, action: PayloadAction<Partial<UserProfile>>) {
      if (state.userProfile) {
        state.userProfile = { ...state.userProfile, ...action.payload };
      }
    },
    clearProfile(state) {
      state.userProfile = null;
    },
  },
});

export const {
  fetchProfileStart,
  fetchProfileSuccess,
  fetchProfileFailure,
  updateProfile,
  clearProfile,
} = profileSlice.actions;

export default profileSlice.reducer;

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