import { scan } from "rxjs/operators";
import { initialSharedActionState, sharedReducer } from "./core";
import { getDeviceInfoTask } from "../tasks/getDeviceInfo";
export const initialState = {
    deviceInfo: null,
    ...initialSharedActionState,
};
export function getDeviceInfoAction({ deviceId, deviceName, }) {
    // TODO: to decide: should we push an event if the state is not changing?
    // For ex: when the device is locked with 0x5515: an event with lockedDevice: true is pushed for each retry
    return getDeviceInfoTask({ deviceId, deviceName }).pipe(scan((currentState, event) => {
        switch (event.type) {
            case "taskError":
                return { ...initialState, error: { type: event.error } };
            case "data":
                return {
                    ...currentState,
                    error: null,
                    deviceInfo: event.deviceInfo,
                };
            case "error":
                return {
                    ...currentState,
                    ...sharedReducer({
                        event,
                    }),
                };
        }
    }, initialState));
}
//# sourceMappingURL=getDeviceInfo.js.map