import { createSlice } from "@reduxjs/toolkit";
import {getTables} from "../httpServices/httpServiceSync";

const initialState = {
    tables:[],
    loading: false,
    error: null
}

const tableSlice = createSlice({
    name: "tables",
    initialState,
    reducers:{},
    extraReducers:(builder)=>{
        // Get Tables
        builder.addCase(getTables.pending, (state) => {
            state.loading = true;
            state.error = null;
        })
        builder.addCase(getTables.fulfilled, (state, action) => {
            state.loading = false;
            state.orders = action.payload;
        })
        builder.addCase(getTables.rejected, (state, action) => {
            state.loading = false;
            state.error = action.error.message;
        });
    }
})

export default tableSlice.reducer;