"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VideohubState = void 0;
const Types_1 = require("./Types");
const events_1 = require("events");
class VideohubState extends events_1.EventEmitter {
    constructor() {
        super();
        this.name = undefined;
        this.deviceName = undefined;
        this.inputs = [];
        this.outputs = [];
        this.monitoring = [];
        this.serials = [];
        this.config = {
            inputCount: 0,
            outputCount: 0,
            monitoringCount: 0,
            serialCount: 0
        };
    }
    setName(name) {
        if (this.name !== name) {
            this.name = name;
            this.emit('change', 'general', { type: 'name', value: name });
        }
    }
    setDeviceName(deviceName) {
        if (this.deviceName !== deviceName) {
            this.deviceName = deviceName;
            this.emit('change', 'general', { type: 'deviceName', value: deviceName });
        }
    }
    getItem(type) {
        switch (type) {
            case Types_1.VideohubPort.Input:
                return this.inputs;
            case Types_1.VideohubPort.Output:
                return this.outputs;
            case Types_1.VideohubPort.Serial:
                return this.serials;
            case Types_1.VideohubPort.Monitoring:
                return this.monitoring;
        }
        return [];
    }
    hasItem(type, id) {
        const items = this.getItem(type);
        return items[id] !== undefined;
    }
    /**
     * Returns the desired input object.
     *
     * @param {number} id - the input to fetch
     * @returns {Object} the desired input object
     * @since 1.1.0
     */
    getInput(id) {
        if (this.inputs[id] === undefined) {
            this.inputs[id] = {
                id: id,
                name: 'Input ' + (id + 1),
                status: Types_1.PortStatus.BNC
            };
        }
        return this.inputs[id];
    }
    /**
     * Returns the desired output object.
     *
     * @param {number} id - the output to fetch
     * @returns {Object} the desired output object
     * @since 1.1.0
     */
    getOutput(id) {
        if (this.outputs[id] === undefined) {
            this.outputs[id] = {
                id: id,
                name: 'Output ' + (id + 1),
                status: Types_1.PortStatus.BNC,
                lock: Types_1.PortLockState.Unlocked,
                route: id
            };
        }
        return this.outputs[id];
    }
    /**
     * Returns the desired monitoring output object.
     *
     * @param {number} id - the output to fetch
     * @returns {Object} the desired output object
     * @since 1.1.0
     */
    getMonitoringOutput(id) {
        if (this.monitoring[id] === undefined) {
            this.monitoring[id] = {
                id: id,
                name: 'Output ' + (id + 1),
                status: Types_1.PortStatus.BNC,
                lock: Types_1.PortLockState.Unlocked,
                route: id
            };
        }
        return this.monitoring[id];
    }
    /**
     * Returns the desired serial port object.
     *
     * @param {number} id - the serial port to fetch
     * @returns {Object} the desired serial port object
     * @since 1.1.0
     */
    getSerial(id) {
        if (this.serials[id] === undefined) {
            this.serials[id] = {
                id: id,
                name: 'Serial ' + (id + 1),
                route: id,
                status: Types_1.PortStatus.RS422,
                lock: Types_1.PortLockState.Unlocked,
                direction: Types_1.PortDirection.Auto
            };
        }
        return this.serials[id];
    }
}
exports.VideohubState = VideohubState;
//# sourceMappingURL=VideohubState.js.map