import { User } from "@/services/types";
import { createSlice } from "@reduxjs/toolkit/react";

interface AuthState {
    user: User | null;
    token: string | null;
    roles: string[];
    isLoading: boolean;
  }
  
  const initialState: AuthState = {
    user: null,
    token: null,
    roles: [],
    isLoading: false,
  };
  
  export const authSlice = createSlice({
    name: "auth",
    initialState,
    reducers: {
      setUser: (state, action) => {
        state.user = action.payload;
      },
      setToken: (state, action) => {
        state.token = action.payload;
      },
      setRoles: (state, action) => {
        state.roles = action.payload;
      },
      setIsLoading: (state, action) => {
        state.isLoading = action.payload;
      },
    },
});

export const { setUser, setToken, setRoles, setIsLoading } = authSlice.actions;