import type {User} from "../types/user";
import {createSlice, PayloadAction} from "@reduxjs/toolkit";

interface FamilyState {
    users: User[];
}

const initialState: FamilyState = {
    users: [],
}

export const familySlice = createSlice({
    name: 'family',
    initialState,
    reducers: {
        addUser: (state, action: PayloadAction<User>) => {
            state.users.push(action.payload);
        },
        removeUser: (state, action: PayloadAction<User>) => {
            state.users.splice(state.users.indexOf(action.payload), 1);
        },
        setUsers: (state, action: PayloadAction<User[]>) => {
            state.users = action.payload;
        }
    }
})

export default familySlice.reducer;
