/**
 * Auth slice
 * @description Minimal authentication slice to hold auth state.
 */

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

export interface AuthState {
    isAuthenticated: boolean;
    userEmail?: string;
}

const initialState: AuthState = {
    isAuthenticated: false,
    userEmail: undefined,
};

const authSlice = createSlice({
    name: 'auth',
    initialState,
    reducers: {
        signIn(state, action: PayloadAction<{ email: string }>) {
            state.isAuthenticated = true;
            state.userEmail = action.payload.email;
        },
        signOut(state) {
            state.isAuthenticated = false;
            state.userEmail = undefined;
        },
    },
});

export const { signIn, signOut } = authSlice.actions;
export const authReducer = authSlice.reducer;

