import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { Scopes } from "@/enums/Scopes";

interface AuthState {
    loginChallenge: string | null;
    phoneNumber: string | null;
    scope: Scopes[];
}

const initialState: AuthState = {
    loginChallenge: null,
    phoneNumber: null,
    scope: [],
};

export const authSlice = createSlice({
    name: "authentication",
    initialState,
    reducers: {
        setLoginChallenge: (state, action: PayloadAction<string | null>) => {
            state.loginChallenge = action.payload;
        },
        setPhoneNumber: (state, action: PayloadAction<string | null>) => {
            state.phoneNumber = action.payload;
        },
        setScope: (state, action: PayloadAction<Scopes[]>) => {
            state.scope = action.payload;
        }
    },
});

export const { setLoginChallenge, setPhoneNumber, setScope } = authSlice.actions;

export default authSlice.reducer;
