"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.VideohubCommand = void 0;
const LINE_SEPERATOR = '\n';
const REGEX_NUMBER = /^\d+$/;
class KeyValue {
    constructor(key, value) {
        this.key = key;
        this.value = value;
    }
    format() {
        if (typeof this.key === 'number') {
            return this.key + ' ' + this.value;
        }
        return this.key + ': ' + this.value;
    }
    keyNumber() {
        if (typeof this.key === 'number') {
            return this.key;
        }
        return undefined;
    }
    keyString() {
        return '' + this.key;
    }
    valueNumber() {
        if (typeof this.value === 'number') {
            return this.value;
        }
        return undefined;
    }
    valueString() {
        return '' + this.value;
    }
}
// tslint:disable-next-line:max-classes-per-file
class VideohubCommand {
    constructor(header) {
        this.header = header;
        this.parameters = new Array();
    }
    addParameter(key, value) {
        this.parameters.push(new KeyValue(key, value));
    }
    format() {
        const result = [];
        result.push(this.header + ':');
        for (const item of this.parameters) {
            result.push(item.format());
        }
        result.push('');
        return result.join(LINE_SEPERATOR);
    }
    parseParameters(lines) {
        for (const line of lines) {
            const list = line.split(/ /);
            if (list.length < 2) {
                continue;
            }
            const key = list.shift();
            const value = list.join(' ');
            this.addParameter(REGEX_NUMBER.test(key) ? parseInt(key, 10) : key, REGEX_NUMBER.test(value) ? parseInt(value, 10) : value);
        }
    }
}
exports.VideohubCommand = VideohubCommand;
//# sourceMappingURL=Command.js.map