"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBatteryStatusesAction = exports.initialState = void 0;
const operators_1 = require("rxjs/operators");
const core_1 = require("./core");
const getBatteryStatuses_1 = require("../tasks/getBatteryStatuses");
exports.initialState = {
    batteryStatuses: [],
    ...core_1.initialSharedActionState,
};
function getBatteryStatusesAction({ deviceId, deviceName, statuses, }) {
    return (0, getBatteryStatuses_1.getBatteryStatusTask)({ deviceId, deviceName, statuses }).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,
                    lockedDevice: false,
                    batteryStatuses: [...currentState.batteryStatuses, event.batteryStatus],
                };
            case "error":
                return {
                    ...currentState,
                    ...(0, core_1.sharedReducer)({
                        event,
                    }),
                };
        }
    }, exports.initialState));
}
exports.getBatteryStatusesAction = getBatteryStatusesAction;
//# sourceMappingURL=getBatteryStatuses.js.map