import { createSlice } from "@reduxjs/toolkit";
import Route from "../components/models/Route";

// step 3 for redux - create slices for each components 
const RouteSlice = createSlice({

    name: 'route',

    initialState: {
        RouteState: new Route(),
        RouteList: []
    },

    reducers: {

        getRouteById: (state, action) => {
            console.log('route slice reducer');
            state.RouteState = action.payload;
        },

        getAllRoute: (state, action) => {
            console.log('RouteSlice reducers getAllRoute');
            state.RouteList = action.payload;
        },
        deleteRouteById: (state, action) => {
            console.log('RouteSlice reducers deleteRouteById');
            state.RouteList = action.payload;
        },
        updateRoute: (state, action) => {
            console.log('RouteSlice reducers update RouteById');
            state.RouteList = action.payload;
        },
        insertRoute: (state, action) => {
            console.log('RouteSlice reducers addRouteById');
            state.RouteList = action.payload;
        },

        // more methods will be added 
    }
});

export const { getRouteById, getAllRoute, deleteRouteById, updateRoute, insertRoute } = RouteSlice.actions;

export default RouteSlice.reducer;
{'avg_line_length': 29.59090909090909, 'max_line_length': 107, 'alphanum_fraction': 0.5975422427035331, 'licenses': ['MIT'], 'repository_name': 'vaibhavdsgit/bus-reservation-ui', 'path': 'src/redux/RouteSlice.js', 'size': 1302, 'lang': 'JavaScript'}