// Third-party Imports
import type { PayloadAction } from '@reduxjs/toolkit'
import { createSlice } from '@reduxjs/toolkit'

// Type Imports

// Data Imports
import { User } from '../../types/services/user'

const initialState: { currentUser: User } = {
  currentUser: {
      id: '',
      organization_id: '',
      outlet_id: '',
      name: '',
      email: '',
      role: '',
      permissions: {},
      is_active: false,
      created_at: '',
      updated_at: ''
  }
}

export const userSlice = createSlice({
  name: 'user',
  initialState,
  reducers: {
    setUser: (state, action: PayloadAction<User>) => {
      state.currentUser = action.payload
    },
    resetUser: state => {
      state.currentUser = initialState.currentUser
    }
  }
})

export const { setUser, resetUser } = userSlice.actions

export default userSlice.reducer
