"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const matter_controller_1 = require("../modules/matter-controller");
const matter_device_1 = require("../modules/matter-device");
function default_1(RED) {
    function MatterDeviceNode(config) {
        const node = this;
        RED.nodes.createNode(node, config);
        const server = RED.nodes.getNode(config.server);
        if (server == null) {
            node.error(`Associated matter-server node (${config.server}) not found`);
            return;
        }
        const controller = new matter_controller_1.MatterController(config.pairingcode, config.ip, config.port);
        server.emit('add_commissioning_controller', node.id, controller.commissioningController);
        controller.onStatusChange((status) => {
            console.log('status', status);
            const updateStatusMessage = {
                type: matter_device_1.DeviceType.OnOffLightDevice,
                status,
            };
            node.emit('status_change', updateStatusMessage);
        });
    }
    RED.nodes.registerType('matter-controller', MatterDeviceNode);
}
exports.default = default_1;
