"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDeviceInfoAction = exports.initialState = void 0;
const operators_1 = require("rxjs/operators");
const core_1 = require("./core");
const getDeviceInfo_1 = require("../tasks/getDeviceInfo");
exports.initialState = {
    deviceInfo: null,
    ...core_1.initialSharedActionState,
};
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 (0, getDeviceInfo_1.getDeviceInfoTask)({ deviceId, deviceName }).pipe((0, operators_1.scan)((currentState, event) => {
        switch (event.type) {
            case "taskError":
                return { ...exports.initialState, error: { type: event.error } };
            case "data":
                return {
                    ...currentState,
                    error: null,
                    deviceInfo: event.deviceInfo,
                };
            case "error":
                return {
                    ...currentState,
                    ...(0, core_1.sharedReducer)({
                        event,
                    }),
                };
        }
    }, exports.initialState));
}
exports.getDeviceInfoAction = getDeviceInfoAction;
//# sourceMappingURL=getDeviceInfo.js.map