import { TapStreamReader, TapStreamWriter, enumKeyOrValueToNumber, StringConverter, TlvBundleConverter } from '@iotize/tap/client/impl';
import { TapRequestFrame } from '@iotize/tap/client/api';
import { converters } from '@iotize/tap/service/core';
import { bundleConverters } from '@iotize/tap/service/impl/bundle';
import { AbstractService, extendServiceContainer } from '@iotize/tap';

var VariableType;
(function (VariableType) {
    /* tslint:disable */
    /**
     * This file was automatically generated by json-schema-to-typescript.
     * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
     * and run json-schema-to-typescript to regenerate this file.
     */
    let Data;
    (function (Data) {
        Data[Data["BOOLEAN"] = 0] = "BOOLEAN";
        Data[Data["INT8"] = 1] = "INT8";
        Data[Data["INT16"] = 2] = "INT16";
        Data[Data["INT32"] = 3] = "INT32";
        Data[Data["ASCII"] = 8] = "ASCII";
        Data[Data["FLOAT32"] = 19] = "FLOAT32";
        Data[Data["UINT8"] = 33] = "UINT8";
        Data[Data["UINT16"] = 34] = "UINT16";
        Data[Data["UINT32"] = 35] = "UINT32";
    })(Data = VariableType.Data || (VariableType.Data = {}));
    /* tslint:disable */
    /**
     * This file was automatically generated by json-schema-to-typescript.
     * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
     * and run json-schema-to-typescript to regenerate this file.
     */
    let Domain;
    (function (Domain) {
        Domain[Domain["TARGET"] = 0] = "TARGET";
        Domain[Domain["GPIO"] = 1] = "GPIO";
        Domain[Domain["IN_TAP_STATIC"] = 2] = "IN_TAP_STATIC";
        Domain[Domain["IN_TAP_VOLATIL"] = 3] = "IN_TAP_VOLATIL";
    })(Domain = VariableType.Domain || (VariableType.Domain = {}));
})(VariableType || (VariableType = {}));

/**
 *   Generated file. Do not edit
 */
TapStreamReader.prototype.readModbusVariableAddress = function () {
    const model = {};
    model.functionCode = this.readUnsigned(1);
    model.slave = this.readUnsigned(1);
    model.address = this.readUnsigned(2);
    return model;
};
TapStreamReader.prototype.readVariableType = function () {
    const model = {};
    model.domain = this.readBits(2);
    model.data = this.readBits(6);
    return model;
};
TapStreamReader.prototype.readVariableMeta = function () {
    const model = {};
    model.name = this.readStringTerminator(":");
    model.unit = this.readString();
    return model;
};
// TapStreamWriter.prototype.write(model: ModbusVariableAddress) : TapStreamWriter{
//     return this.writeModbusVariableAddress(model)
// }
TapStreamWriter.prototype.writeModbusVariableAddress = function (model) {
    this.writeUnsigned(model.functionCode, 1);
    this.writeUnsigned(model.slave, 1);
    this.writeUnsigned(model.address, 2);
    return this;
};
// TapStreamWriter.prototype.write(model: VariableType) : TapStreamWriter{
//     return this.writeVariableType(model)
// }
TapStreamWriter.prototype.writeVariableType = function (model) {
    this.writeBitsInt(enumKeyOrValueToNumber(model.domain, VariableType.Domain), 2);
    this.writeBitsInt(enumKeyOrValueToNumber(model.data, VariableType.Data), 6);
    return this;
};
// TapStreamWriter.prototype.write(model: VariableMeta) : TapStreamWriter{
//     return this.writeVariableMeta(model)
// }
TapStreamWriter.prototype.writeVariableMeta = function (model) {
    this.writeString(model.name + ":");
    this.writeString(model.unit);
    return this;
};

/**
 *   Generated file. Do not edit
 */
class ModbusVariableAddressConverter {
    encode(model, stream = new TapStreamWriter()) {
        stream.writeModbusVariableAddress(model);
        return stream.toBytes;
    }
    decode(data) {
        const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readModbusVariableAddress();
    }
}
class VariableTypeConverter {
    encode(model, stream = new TapStreamWriter()) {
        stream.writeVariableType(model);
        return stream.toBytes;
    }
    decode(data) {
        const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readVariableType();
    }
}
class VariableMetaConverter {
    encode(model, stream = new TapStreamWriter()) {
        stream.writeVariableMeta(model);
        return stream.toBytes;
    }
    decode(data) {
        const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readVariableMeta();
    }
}

/**
 *   Generated file. Do not edit
 */
const modbusVariableAddress = new ModbusVariableAddressConverter();
const variableType = new VariableTypeConverter();
const variableMeta = new VariableMetaConverter();

var serviceConverters = /*#__PURE__*/Object.freeze({
    __proto__: null,
    modbusVariableAddress: modbusVariableAddress,
    variableType: variableType,
    variableMeta: variableMeta
});

/**
 *   Generated file. Do not edit
 */
const allConverters = Object.assign(Object.assign(Object.assign({}, converters), serviceConverters), bundleConverters);
const SERVICE_CALLS = {
    getVariableAddress: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/variable/{variableId}/variable-address",
        path: "/1029/{variableId}/0",
        responseBodyDecoder: allConverters.uint32
    },
    putVariableAddress: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: "/variable/{variableId}/variable-address",
        path: "/1029/{variableId}/0",
        bodyEncoder: allConverters.uint32
    },
    putModbusVariableAddress: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: "/variable/{variableId}/modbus-variable-address",
        path: "/1029/{variableId}/0",
        bodyEncoder: allConverters.modbusVariableAddress
    },
    getType: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/variable/{variableId}/type",
        path: "/1029/{variableId}/1",
        responseBodyDecoder: allConverters.variableType
    },
    putType: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: "/variable/{variableId}/type",
        path: "/1029/{variableId}/1",
        bodyEncoder: allConverters.variableType
    },
    getRawMeta: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/variable/{variableId}/raw-meta",
        path: "/1029/{variableId}/8"
    },
    putRawMeta: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: "/variable/{variableId}/raw-meta",
        path: "/1029/{variableId}/8"
    },
    getMeta: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/variable/{variableId}/meta",
        path: "/1029/{variableId}/8",
        responseBodyDecoder: allConverters.variableMeta
    },
    putMeta: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: "/variable/{variableId}/meta",
        path: "/1029/{variableId}/8",
        bodyEncoder: allConverters.variableMeta
    },
    getUnit: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/variable/{variableId}/unit",
        path: "/1029/{variableId}/9",
        responseBodyDecoder: allConverters.ascii
    },
    putUnit: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: "/variable/{variableId}/unit",
        path: "/1029/{variableId}/9",
        bodyEncoder: allConverters.ascii
    },
    getNumberOfElements: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/variable/{variableId}/number-of-elements",
        path: "/1029/{variableId}/2",
        responseBodyDecoder: allConverters.uint8
    },
    putNumberOfElements: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: "/variable/{variableId}/number-of-elements",
        path: "/1029/{variableId}/2",
        bodyEncoder: allConverters.uint8
    },
    getCurrentAccess: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/variable/{variableId}/current-access",
        path: "/1029/{variableId}/3",
        responseBodyDecoder: allConverters.readWriteRights
    },
    readProfile: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/variable/read-profile",
        path: "/1029//4"
    },
    getValue: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/variable/{variableId}/value",
        path: "/1029/{variableId}/4"
    },
    setValue: {
        method: TapRequestFrame.MethodType.POST,
        pathAlias: "/variable/{variableId}/value",
        path: "/1029/{variableId}/5"
    },
    putValue: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: "/variable/{variableId}/value",
        path: "/1029/{variableId}/4"
    },
    getBundleId: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/variable/{variableId}/bundle/id",
        path: "/1029/{variableId}/6",
        responseBodyDecoder: allConverters.uint16
    },
    putBundleId: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: "/variable/{variableId}/bundle/id",
        path: "/1029/{variableId}/6",
        bodyEncoder: allConverters.uint16
    },
    getBundleValues: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/variable/{variableId}/bundle/values",
        path: "/1029/{variableId}/7"
    },
    create: {
        method: TapRequestFrame.MethodType.POST,
        pathAlias: "/variable/{variableId}/create",
        path: "/1029/{variableId}/65535",
        bodyEncoder: allConverters.uint8
    }
};

class VariableService extends AbstractService {
    constructor() {
        super(...arguments);
        this.resources = SERVICE_CALLS;
    }
    /**
     * Get variable address
     *
     * LWM2M path: /1029/{variableId}/0
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return
     */
    getVariableAddress(
    /*
     * ID of the variable
     */
    variableId) {
        return this.serviceCallRunner.execute(this.getVariableAddressCall(variableId));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/0
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return call options
     */
    getVariableAddressCall(
    /*
     * ID of the variable
     */
    variableId) {
        const callOptions = Object.assign({}, this.resources.getVariableAddress);
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Write variable address
     *
     * LWM2M path: /1029/{variableId}/0
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param address input
     * @return
     */
    putVariableAddress(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * New address of the variable
     */
    address) {
        return this.serviceCallRunner.execute(this.putVariableAddressCall(variableId, address));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/0
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param address input
     * @return call options
     */
    putVariableAddressCall(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * New address of the variable
     */
    address) {
        const callOptions = Object.assign({}, this.resources.putVariableAddress);
        callOptions.body = address;
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Write modbus variable address
     *
     * LWM2M path: /1029/{variableId}/0
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param address input
     * @return
     */
    putModbusVariableAddress(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * New address of the variable
     */
    address) {
        return this.serviceCallRunner.execute(this.putModbusVariableAddressCall(variableId, address));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/0
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param address input
     * @return call options
     */
    putModbusVariableAddressCall(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * New address of the variable
     */
    address) {
        const callOptions = Object.assign({}, this.resources.putModbusVariableAddress);
        callOptions.body = address;
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Get data type for variable
     *
     * LWM2M path: /1029/{variableId}/1
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return
     */
    getType(
    /*
     * ID of the variable
     */
    variableId) {
        return this.serviceCallRunner.execute(this.getTypeCall(variableId));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/1
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return call options
     */
    getTypeCall(
    /*
     * ID of the variable
     */
    variableId) {
        const callOptions = Object.assign({}, this.resources.getType);
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Get data type for variable
     *
     * LWM2M path: /1029/{variableId}/1
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param type input
     * @return
     */
    putType(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * variable type
     */
    type) {
        return this.serviceCallRunner.execute(this.putTypeCall(variableId, type));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/1
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param type input
     * @return call options
     */
    putTypeCall(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * variable type
     */
    type) {
        const callOptions = Object.assign({}, this.resources.putType);
        callOptions.body = type;
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Get variable meta
     *
     * LWM2M path: /1029/{variableId}/8
     *
     * @tapVersion(">=1.73")
     * @param variableId input
     * @return
     */
    getRawMeta(
    /*
     * ID of the variable
     */
    variableId) {
        return this.serviceCallRunner.execute(this.getRawMetaCall(variableId));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/8
     *
     * @tapVersion(">=1.73")
     * @param variableId input
     * @return call options
     */
    getRawMetaCall(
    /*
     * ID of the variable
     */
    variableId) {
        const callOptions = Object.assign({}, this.resources.getRawMeta);
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Write variable meta
     *
     * LWM2M path: /1029/{variableId}/8
     *
     * @tapVersion(">=1.73")
     * @param variableId input
     * @param meta input
     * @return
     */
    putRawMeta(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * Variable meta
     */
    meta) {
        return this.serviceCallRunner.execute(this.putRawMetaCall(variableId, meta));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/8
     *
     * @tapVersion(">=1.73")
     * @param variableId input
     * @param meta input
     * @return call options
     */
    putRawMetaCall(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * Variable meta
     */
    meta) {
        const callOptions = Object.assign({}, this.resources.putRawMeta);
        callOptions.body = meta;
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Get variable meta
     *
     * LWM2M path: /1029/{variableId}/8
     *
     * @tapVersion(">=1.73")
     * @param variableId input
     * @return
     */
    getMeta(
    /*
     * ID of the variable
     */
    variableId) {
        return this.serviceCallRunner.execute(this.getMetaCall(variableId));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/8
     *
     * @tapVersion(">=1.73")
     * @param variableId input
     * @return call options
     */
    getMetaCall(
    /*
     * ID of the variable
     */
    variableId) {
        const callOptions = Object.assign({}, this.resources.getMeta);
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Write variable meta
     *
     * LWM2M path: /1029/{variableId}/8
     *
     * @tapVersion(">=1.73")
     * @param variableId input
     * @param meta input
     * @return
     */
    putMeta(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * Variable meta
     */
    meta) {
        return this.serviceCallRunner.execute(this.putMetaCall(variableId, meta));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/8
     *
     * @tapVersion(">=1.73")
     * @param variableId input
     * @param meta input
     * @return call options
     */
    putMetaCall(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * Variable meta
     */
    meta) {
        const callOptions = Object.assign({}, this.resources.putMeta);
        callOptions.body = meta;
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Get variable unit
     *
     * LWM2M path: /1029/{variableId}/9
     *
     * @deprecated
     * @tapVersion(">=1.60")
     * @param variableId input
     * @return
     */
    getUnit(
    /*
     * Variable id
     */
    variableId) {
        return this.serviceCallRunner.execute(this.getUnitCall(variableId));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/9
     *
     * @deprecated
     * @tapVersion(">=1.60")
     * @param variableId input
     * @return call options
     */
    getUnitCall(
    /*
     * Variable id
     */
    variableId) {
        const callOptions = Object.assign({}, this.resources.getUnit);
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Write variable unit
     *
     * LWM2M path: /1029/{variableId}/9
     *
     * @deprecated
     * @tapVersion(">=1.60")
     * @param variableId input
     * @param address input
     * @return
     */
    putUnit(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * Variable unit
     */
    address) {
        return this.serviceCallRunner.execute(this.putUnitCall(variableId, address));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/9
     *
     * @deprecated
     * @tapVersion(">=1.60")
     * @param variableId input
     * @param address input
     * @return call options
     */
    putUnitCall(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * Variable unit
     */
    address) {
        const callOptions = Object.assign({}, this.resources.putUnit);
        callOptions.body = address;
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Get variable array size
     *
     * LWM2M path: /1029/{variableId}/2
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return
     */
    getNumberOfElements(
    /*
     * ID of the variable
     */
    variableId) {
        return this.serviceCallRunner.execute(this.getNumberOfElementsCall(variableId));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/2
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return call options
     */
    getNumberOfElementsCall(
    /*
     * ID of the variable
     */
    variableId) {
        const callOptions = Object.assign({}, this.resources.getNumberOfElements);
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Write variable array size
     *
     * LWM2M path: /1029/{variableId}/2
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param value input
     * @return
     */
    putNumberOfElements(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * New number of element for this variable
     */
    value) {
        return this.serviceCallRunner.execute(this.putNumberOfElementsCall(variableId, value));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/2
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param value input
     * @return call options
     */
    putNumberOfElementsCall(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     * New number of element for this variable
     */
    value) {
        const callOptions = Object.assign({}, this.resources.putNumberOfElements);
        callOptions.body = value;
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Get access rights for the variable
     *
     * LWM2M path: /1029/{variableId}/3
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return
     */
    getCurrentAccess(
    /*
     * ID of the variable
     */
    variableId) {
        return this.serviceCallRunner.execute(this.getCurrentAccessCall(variableId));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/3
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return call options
     */
    getCurrentAccessCall(
    /*
     * ID of the variable
     */
    variableId) {
        const callOptions = Object.assign({}, this.resources.getCurrentAccess);
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Get all variable values for the current profile
     *
     * LWM2M path: /1029//4
     *
     * @tapVersion(">=")
     * @return
     */
    readProfile() {
        return this.serviceCallRunner.execute(this.readProfileCall());
    }
    /**
     *
     *
     * LWM2M path: /1029//4
     *
     * @tapVersion(">=")
     * @return call options
     */
    readProfileCall() {
        const callOptions = Object.assign({}, this.resources.readProfile);
        return callOptions;
    }
    /**
     * Get variable value
     *
     * LWM2M path: /1029/{variableId}/4
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return
     */
    getValue(
    /*
     * ID of the variable
     */
    variableId) {
        return this.serviceCallRunner.execute(this.getValueCall(variableId));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/4
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return call options
     */
    getValueCall(
    /*
     * ID of the variable
     */
    variableId) {
        const callOptions = Object.assign({}, this.resources.getValue);
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Set variable value
     *
     * LWM2M path: /1029/{variableId}/5
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param value input
     * @return
     */
    setValue(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     *
     */
    value) {
        return this.serviceCallRunner.execute(this.setValueCall(variableId, value));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/5
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param value input
     * @return call options
     */
    setValueCall(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     *
     */
    value) {
        const callOptions = Object.assign({}, this.resources.setValue);
        callOptions.body = value;
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Set variable value
     *
     * LWM2M path: /1029/{variableId}/4
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param value input
     * @return
     */
    putValue(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     *
     */
    value) {
        return this.serviceCallRunner.execute(this.putValueCall(variableId, value));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/4
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param value input
     * @return call options
     */
    putValueCall(
    /*
     * ID of the variable
     */
    variableId, 
    /*
     *
     */
    value) {
        const callOptions = Object.assign({}, this.resources.putValue);
        callOptions.body = value;
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Get variable bundle id
     *
     * LWM2M path: /1029/{variableId}/6
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return
     */
    getBundleId(
    /*
     *
     */
    variableId) {
        return this.serviceCallRunner.execute(this.getBundleIdCall(variableId));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/6
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return call options
     */
    getBundleIdCall(
    /*
     *
     */
    variableId) {
        const callOptions = Object.assign({}, this.resources.getBundleId);
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Write variable bundle id
     *
     * LWM2M path: /1029/{variableId}/6
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param value input
     * @return
     */
    putBundleId(
    /*
     *
     */
    variableId, 
    /*
     *
     */
    value) {
        return this.serviceCallRunner.execute(this.putBundleIdCall(variableId, value));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/6
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param value input
     * @return call options
     */
    putBundleIdCall(
    /*
     *
     */
    variableId, 
    /*
     *
     */
    value) {
        const callOptions = Object.assign({}, this.resources.putBundleId);
        callOptions.body = value;
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Get variable bundle values (formated as a TLV)
     *
     * LWM2M path: /1029/{variableId}/7
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return
     */
    getBundleValues(
    /*
     *
     */
    variableId) {
        return this.serviceCallRunner.execute(this.getBundleValuesCall(variableId));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/7
     *
     * @tapVersion(">=")
     * @param variableId input
     * @return call options
     */
    getBundleValuesCall(
    /*
     *
     */
    variableId) {
        const callOptions = Object.assign({}, this.resources.getBundleValues);
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
    /**
     * Write variable bundle id
     *
     * LWM2M path: /1029/{variableId}/65535
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param extraSize input
     * @return
     */
    create(
    /*
     *
     */
    variableId, 
    /*
     * extra data size in bytes
     */
    extraSize) {
        return this.serviceCallRunner.execute(this.createCall(variableId, extraSize));
    }
    /**
     *
     *
     * LWM2M path: /1029/{variableId}/65535
     *
     * @tapVersion(">=")
     * @param variableId input
     * @param extraSize input
     * @return call options
     */
    createCall(
    /*
     *
     */
    variableId, 
    /*
     * extra data size in bytes
     */
    extraSize) {
        const callOptions = Object.assign({}, this.resources.create);
        callOptions.body = extraSize;
        callOptions.pathParameters = {
            variableId: variableId
        };
        return callOptions;
    }
}

const utf8Converter = new StringConverter('utf8');
VariableService.prototype.getMeta = function (id) {
    return this.getRawMeta(id).then(response => {
        const metaResponse = response;
        metaResponse.setBodyDecoder({
            decode: (raw) => {
                const [name, ...extra] = utf8Converter.decode(raw).split(':');
                return {
                    name,
                    unit: extra.length > 0 ? extra[0] : ''
                };
            }
        });
        return metaResponse;
    });
};
VariableService.prototype.putMeta = function (id, data) {
    const encoded = utf8Converter.encode(`${data.name}:${data.unit}`);
    return this.putRawMeta(id, encoded);
};
VariableService.prototype.getAllValues = function () {
    return this.readProfile().then(responseInterface => {
        const response = responseInterface;
        if (response.isSuccessful()) {
            const data = response.rawBody();
            const converter = new TlvBundleConverter();
            const mappings = converter.decode(data);
            response.setBody(mappings);
        }
        return response;
    });
};

class VariableMetaConfigConverter {
    constructor() {
        this.utf8Converter = new StringConverter('utf8');
    }
    encode(data) {
        return this.utf8Converter.encode(`${data.name || ''}:${data.unit || ''}`);
    }
    decode(data) {
        const str = this.utf8Converter.decode(data);
        const output = str.split(':');
        return {
            name: output[0],
            unit: output.length >= 2 ? output[1] : ''
        };
    }
}

const _TAP_SERVICE_EXTENSION_VARIABLE_ = extendServiceContainer("variable", VariableService);

// Replace generated converter as there is a bug in generated converter (decoding does not split info with character ':')
const variableMetaConfigConverter = new VariableMetaConfigConverter();
SERVICE_CALLS.getMeta.responseBodyDecoder = variableMetaConfigConverter;
SERVICE_CALLS.putMeta.bodyEncoder = variableMetaConfigConverter;

/**
 * Generated bundle index. Do not edit.
 */

export { ModbusVariableAddressConverter, SERVICE_CALLS as VARIABLE_SERVICE_CALLS, VariableMetaConfigConverter, VariableMetaConverter, VariableService, VariableType, VariableTypeConverter, _TAP_SERVICE_EXTENSION_VARIABLE_, serviceConverters as variableConverters };
//# sourceMappingURL=iotize-tap-service-impl-variable.js.map
