import { scan } from "rxjs/operators";
import { initialSharedActionState, sharedReducer } from "./core";
import { getBatteryStatusTask } from "../tasks/getBatteryStatuses";
export const initialState = {
    batteryStatuses: [],
    ...initialSharedActionState,
};
export function getBatteryStatusesAction({ deviceId, deviceName, statuses, }) {
    return getBatteryStatusTask({ deviceId, deviceName, statuses }).pipe(scan((currentState, event) => {
        switch (event.type) {
            case "taskError":
                return { ...initialState, error: { type: event.error } };
            case "data":
                return {
                    ...currentState,
                    error: null,
                    lockedDevice: false,
                    batteryStatuses: [...currentState.batteryStatuses, event.batteryStatus],
                };
            case "error":
                return {
                    ...currentState,
                    ...sharedReducer({
                        event,
                    }),
                };
        }
    }, initialState));
}
//# sourceMappingURL=getBatteryStatuses.js.map