import {BluetoothDevice} from "react-native-bluetooth-classic";
import {createSlice, PayloadAction} from "@reduxjs/toolkit";

export interface ScannerState {
    isConnected: boolean;
    deviceAddress?: string;
}

const initialState: ScannerState = {
    isConnected: false,
    deviceAddress: undefined
}

export const scannerSlice = createSlice({
    name: "scannerState",
    initialState,
    reducers: {
        setDevice(state, action: PayloadAction<{ deviceAddress: string }>) {
            state.deviceAddress = action.payload.deviceAddress;
        },
        setIsConnected(state, action: PayloadAction<{ isConnected: boolean }>) {
            state.isConnected = action.payload.isConnected
        }


    }
})

export const {setDevice, setIsConnected} = scannerSlice.actions
export default scannerSlice.reducer