import { createSlice } from '@reduxjs/toolkit'
import type { PayloadAction } from '@reduxjs/toolkit'

export interface WebSocketState {
  ws: WebSocket | null
}

const initialState: WebSocketState = {
  ws: null,
}

export const websocketSlice = createSlice({
  name: 'websocket',
  initialState,
  reducers: {
    setWebSocket: (state, action: PayloadAction<WebSocket>) => {
      state.ws = action.payload
    },
  },
})

export const { setWebSocket } = websocketSlice.actions

export default websocketSlice.reducer
