"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
    if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.StatusGateway = void 0;
const common_1 = require("@nestjs/common");
const websockets_1 = require("@nestjs/websockets");
const ws_guard_1 = require("../../core/auth/guards/ws.guard");
const plugins_service_1 = require("../plugins/plugins.service");
const status_service_1 = require("./status.service");
let StatusGateway = class StatusGateway {
    constructor(statusService, pluginsService) {
        this.statusService = statusService;
        this.pluginsService = pluginsService;
    }
    async getDashboardLayout() {
        try {
            return await this.statusService.getDashboardLayout();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async setDashboardLayout(client, payload) {
        try {
            return await this.statusService.setDashboardLayout(payload);
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async homebridgeVersionCheck() {
        try {
            return await this.pluginsService.getHomebridgePackage();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async homebridgeUiVersionCheck() {
        try {
            return await this.pluginsService.getHomebridgeUiPackage();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async npmVersionCheck() {
        try {
            return await this.pluginsService.getNpmPackage();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async dockerVersionCheck() {
        try {
            return await this.statusService.getDockerDetails();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async nodeJsVersionCheck() {
        try {
            return await this.statusService.getNodeJsVersionInfo();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async getOutOfDatePlugins() {
        try {
            return await this.pluginsService.getOutOfDatePlugins();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async getHomebridgeServerInfo() {
        try {
            return await this.statusService.getHomebridgeServerInfo();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async getServerCpuInfo() {
        try {
            return await this.statusService.getServerCpuInfo();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async getServerMemoryInfo() {
        try {
            return await this.statusService.getServerMemoryInfo();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async getServerNetworkInfo(client, payload) {
        try {
            return await this.statusService.getCurrentNetworkUsage(payload.netInterfaces || []);
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async getServerUptimeInfo() {
        try {
            return await this.statusService.getServerUptimeInfo();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async getHomebridgePairingPin() {
        try {
            return await this.statusService.getHomebridgePairingPin();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async getHomebridgeStatus() {
        try {
            return await this.statusService.getHomebridgeStatus();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
    async serverStatus(client) {
        this.statusService.watchStats(client);
    }
    async getRaspberryPiThrottledStatus() {
        try {
            return await this.statusService.getRaspberryPiThrottledStatus();
        }
        catch (e) {
            return new websockets_1.WsException(e.message);
        }
    }
};
exports.StatusGateway = StatusGateway;
__decorate([
    (0, websockets_1.SubscribeMessage)('get-dashboard-layout'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "getDashboardLayout", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('set-dashboard-layout'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "setDashboardLayout", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('homebridge-version-check'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "homebridgeVersionCheck", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('homebridge-ui-version-check'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "homebridgeUiVersionCheck", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('npm-version-check'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "npmVersionCheck", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('docker-version-check'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "dockerVersionCheck", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('nodejs-version-check'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "nodeJsVersionCheck", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('get-out-of-date-plugins'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "getOutOfDatePlugins", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('get-homebridge-server-info'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "getHomebridgeServerInfo", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('get-server-cpu-info'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "getServerCpuInfo", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('get-server-memory-info'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "getServerMemoryInfo", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('get-server-network-info'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object, Object]),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "getServerNetworkInfo", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('get-server-uptime-info'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "getServerUptimeInfo", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('get-homebridge-pairing-pin'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "getHomebridgePairingPin", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('get-homebridge-status'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "getHomebridgeStatus", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('monitor-server-status'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", [Object]),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "serverStatus", null);
__decorate([
    (0, websockets_1.SubscribeMessage)('get-raspberry-pi-throttled-status'),
    __metadata("design:type", Function),
    __metadata("design:paramtypes", []),
    __metadata("design:returntype", Promise)
], StatusGateway.prototype, "getRaspberryPiThrottledStatus", null);
exports.StatusGateway = StatusGateway = __decorate([
    (0, common_1.UseGuards)(ws_guard_1.WsGuard),
    (0, websockets_1.WebSocketGateway)({
        namespace: 'status',
        allowEIO3: true,
        cors: {
            origin: ['http://localhost:8080', 'http://localhost:4200'],
            credentials: true,
        },
    }),
    __metadata("design:paramtypes", [status_service_1.StatusService,
        plugins_service_1.PluginsService])
], StatusGateway);
//# sourceMappingURL=status.gateway.js.map