"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IccDeviceXApi = void 0;
const icc_api_1 = require("../icc-api");
const AuthenticationProvider_1 = require("./auth/AuthenticationProvider");
const Connection_1 = require("../icc-api/model/Connection");
const websocket_1 = require("./utils/websocket");
// noinspection JSUnusedGlobalSymbols
class IccDeviceXApi extends icc_api_1.IccDeviceApi {
    constructor(host, headers, authenticationProvider = new AuthenticationProvider_1.NoAuthenticationProvider(), userApi, authApi, fetchImpl = typeof window !== 'undefined'
        ? window.fetch
        : typeof self !== 'undefined'
            ? self.fetch
            : fetch) {
        super(host, headers, authenticationProvider, fetchImpl);
        this.userApi = userApi;
        this.authApi = authApi;
    }
    /**
     * Subscribes to real-time device events using a WebSocket connection.
     * @param eventTypes the types of events to listen for (e.g. 'CREATE', 'UPDATE', 'DELETE').
     * @param filter an optional filter to restrict which device events trigger the callback.
     * @param eventFired the callback function invoked when a matching device event is received.
     * @param options optional subscription configuration such as connection parameters and retry behaviour.
     * @return a connection object that can be used to manage the WebSocket subscription lifecycle.
     */
    subscribeToDeviceEvents(eventTypes_1, filter_1, eventFired_1) {
        return __awaiter(this, arguments, void 0, function* (eventTypes, filter, eventFired, options = {}) {
            return (0, websocket_1.subscribeToEntityEvents)(this.host, this.authApi, 'Device', eventTypes, filter, eventFired, options).then((rs) => new Connection_1.ConnectionImpl(rs));
        });
    }
}
exports.IccDeviceXApi = IccDeviceXApi;
//# sourceMappingURL=icc-device-x-api.js.map