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

import { UserType } from '@/modules/@common/user/types';

type StateType = {
  lastUpdate?: string | null;
  isUserActivated: boolean;
  userData?: UserType | null;
};

const initialState: StateType = {
  lastUpdate: null,
  isUserActivated: false,
  userData: null,
};

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

  reducers: {
    getUserDataAction: (state) => state,
    setUserDataAction: (state, action: PayloadAction<UserType>) => {
      state.userData = action.payload;
    },
  },
});

export const { getUserDataAction, setUserDataAction } = slice.actions;

export default slice.reducer;
