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

/**
 *   Generated file. Do not edit
 */
TapStreamReader.prototype.readReadWriteRights = function () {
    const model = {};
    model.header = this.readUnsigned(1);
    model.groupId = this.readUnsigned((model.header === undefined ? 0 : model.header) == 0x61 ? 2 : 1);
    this.forwardBits(6);
    model.write = this.readBoolean(1);
    model.read = this.readBoolean(1);
    return model;
};
// TapStreamWriter.prototype.write(model: ReadWriteRights) : TapStreamWriter{
//     return this.writeReadWriteRights(model)
// }
TapStreamWriter.prototype.writeReadWriteRights = function (model) {
    this.writeUnsigned(model.header !== undefined
        ? model.header
        : model.groupId > 255
            ? 0x61
            : 0x41, 1);
    this.writeUnsigned(model.groupId, (model.header === undefined ? 0 : model.header) == 0x61 ? 2 : 1);
    this.forwardBits(6);
    this.writeBoolean(model.write, 1);
    this.writeBoolean(model.read, 1);
    return this;
};

/**
 *   Generated file. Do not edit
 */
class ReadWriteRightsConverter {
    encode(model, stream = new TapStreamWriter()) {
        stream.writeReadWriteRights(model);
        return stream.toBytes;
    }
    decode(data) {
        const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readReadWriteRights();
    }
}

/**
 *   Generated file. Do not edit
 */
const readWriteRights = new ReadWriteRightsConverter();

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

/**
 *   Generated file. Do not edit
 */
const allConverters = Object.assign(Object.assign({}, converters), serviceConverters);
const SERVICE_CALLS = {
    putAcl: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: '/bundle/{bundleId}/acl',
        path: '/1028/{bundleId}/0',
        bodyEncoder: allConverters.readWriteRights,
    },
    getValues: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: '/bundle/{bundleId}/values',
        path: '/1028/{bundleId}/1',
    },
    getDataLogPeriod: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: '/bundle/{bundleId}/data-log-period',
        path: '/1028/{bundleId}/2',
        responseBodyDecoder: allConverters.uint32,
    },
    putDataLogPeriod: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: '/bundle/{bundleId}/data-log-period',
        path: '/1028/{bundleId}/2',
        bodyEncoder: allConverters.uint32,
    },
    getDataLogCryptoGroupId: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: '/bundle/{bundleId}/data-log-crypto-group-id',
        path: '/1028/{bundleId}/3',
        responseBodyDecoder: allConverters.uint16,
    },
    putDataLogCryptoGroupId: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: '/bundle/{bundleId}/data-log-crypto-group-id',
        path: '/1028/{bundleId}/3',
        bodyEncoder: allConverters.uint16,
    },
    create: {
        method: TapRequestFrame.MethodType.POST,
        pathAlias: '/bundle/{bundleId}/create',
        path: '/1028/{bundleId}/65535',
    },
    getName: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: '/bundle/{bundleId}/name',
        path: '/1028/{bundleId}/4',
        responseBodyDecoder: allConverters.ascii,
    },
    putName: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: '/bundle/{bundleId}/name',
        path: '/1028/{bundleId}/4',
        bodyEncoder: allConverters.ascii,
    },
};

class BundleService extends AbstractService {
    constructor() {
        super(...arguments);
        this.resources = SERVICE_CALLS;
    }
    /**
     * Write acls
     *
     * LWM2M path: /1028/{bundleId}/0
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @param rights input
     * @return
     */
    putAcl(
    /*
     * Group id
     */
    bundleId, 
    /*
     * Rights
     */
    rights) {
        return this.serviceCallRunner.execute(this.putAclCall(bundleId, rights));
    }
    /**
     *
     *
     * LWM2M path: /1028/{bundleId}/0
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @param rights input
     * @return call options
     */
    putAclCall(
    /*
     * Group id
     */
    bundleId, 
    /*
     * Rights
     */
    rights) {
        const callOptions = Object.assign({}, this.resources.putAcl);
        callOptions.body = rights;
        callOptions.pathParameters = {
            bundleId: bundleId,
        };
        return callOptions;
    }
    /**
     * Get bundle values
     *
     * LWM2M path: /1028/{bundleId}/1
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @return
     */
    getValues(
    /*
     * Bundle id
     */
    bundleId) {
        return this.serviceCallRunner.execute(this.getValuesCall(bundleId));
    }
    /**
     *
     *
     * LWM2M path: /1028/{bundleId}/1
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @return call options
     */
    getValuesCall(
    /*
     * Bundle id
     */
    bundleId) {
        const callOptions = Object.assign({}, this.resources.getValues);
        callOptions.pathParameters = {
            bundleId: bundleId,
        };
        return callOptions;
    }
    /**
     * Get data log acquisition period
     *
     * LWM2M path: /1028/{bundleId}/2
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @return
     */
    getDataLogPeriod(
    /*
     * 0: no Data log for this bundle. (-1) : Log this bundle whenever one of its variables is written. Other values: number of minutes between each log of the Bundle.
     */
    bundleId) {
        return this.serviceCallRunner.execute(this.getDataLogPeriodCall(bundleId));
    }
    /**
     *
     *
     * LWM2M path: /1028/{bundleId}/2
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @return call options
     */
    getDataLogPeriodCall(
    /*
     * 0: no Data log for this bundle. (-1) : Log this bundle whenever one of its variables is written. Other values: number of minutes between each log of the Bundle.
     */
    bundleId) {
        const callOptions = Object.assign({}, this.resources.getDataLogPeriod);
        callOptions.pathParameters = {
            bundleId: bundleId,
        };
        return callOptions;
    }
    /**
     * Write data-log acquisition period in configuration
     *
     * LWM2M path: /1028/{bundleId}/2
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @param value input
     * @return
     */
    putDataLogPeriod(
    /*
     * Bundle id
     */
    bundleId, 
    /*
     * 0: no Data log for this bundle. (-1) : Log this bundle whenever one of its variables is written. Other values: number of minutes between each log of the Bundle.
     */
    value) {
        return this.serviceCallRunner.execute(this.putDataLogPeriodCall(bundleId, value));
    }
    /**
     *
     *
     * LWM2M path: /1028/{bundleId}/2
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @param value input
     * @return call options
     */
    putDataLogPeriodCall(
    /*
     * Bundle id
     */
    bundleId, 
    /*
     * 0: no Data log for this bundle. (-1) : Log this bundle whenever one of its variables is written. Other values: number of minutes between each log of the Bundle.
     */
    value) {
        const callOptions = Object.assign({}, this.resources.putDataLogPeriod);
        callOptions.body = value;
        callOptions.pathParameters = {
            bundleId: bundleId,
        };
        return callOptions;
    }
    /**
     * Get data log encryption group id
     *
     * LWM2M path: /1028/{bundleId}/3
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @return
     */
    getDataLogCryptoGroupId(
    /*
     * Bundle id
     */
    bundleId) {
        return this.serviceCallRunner.execute(this.getDataLogCryptoGroupIdCall(bundleId));
    }
    /**
     *
     *
     * LWM2M path: /1028/{bundleId}/3
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @return call options
     */
    getDataLogCryptoGroupIdCall(
    /*
     * Bundle id
     */
    bundleId) {
        const callOptions = Object.assign({}, this.resources.getDataLogCryptoGroupId);
        callOptions.pathParameters = {
            bundleId: bundleId,
        };
        return callOptions;
    }
    /**
     * Write data-log acquisition period in configuration
     *
     * LWM2M path: /1028/{bundleId}/3
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @param value input
     * @return
     */
    putDataLogCryptoGroupId(
    /*
     * Bundle id
     */
    bundleId, 
    /*
     *
     */
    value) {
        return this.serviceCallRunner.execute(this.putDataLogCryptoGroupIdCall(bundleId, value));
    }
    /**
     *
     *
     * LWM2M path: /1028/{bundleId}/3
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @param value input
     * @return call options
     */
    putDataLogCryptoGroupIdCall(
    /*
     * Bundle id
     */
    bundleId, 
    /*
     *
     */
    value) {
        const callOptions = Object.assign({}, this.resources.putDataLogCryptoGroupId);
        callOptions.body = value;
        callOptions.pathParameters = {
            bundleId: bundleId,
        };
        return callOptions;
    }
    /**
     * Create a new bundle
     *
     * LWM2M path: /1028/{bundleId}/65535
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @return
     */
    create(
    /*
     * Bundle id
     */
    bundleId) {
        return this.serviceCallRunner.execute(this.createCall(bundleId));
    }
    /**
     *
     *
     * LWM2M path: /1028/{bundleId}/65535
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @return call options
     */
    createCall(
    /*
     * Bundle id
     */
    bundleId) {
        const callOptions = Object.assign({}, this.resources.create);
        callOptions.pathParameters = {
            bundleId: bundleId,
        };
        return callOptions;
    }
    /**
     * Read bundle name
     *
     * LWM2M path: /1028/{bundleId}/4
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @return
     */
    getName(
    /*
     * Bundle id
     */
    bundleId) {
        return this.serviceCallRunner.execute(this.getNameCall(bundleId));
    }
    /**
     *
     *
     * LWM2M path: /1028/{bundleId}/4
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @return call options
     */
    getNameCall(
    /*
     * Bundle id
     */
    bundleId) {
        const callOptions = Object.assign({}, this.resources.getName);
        callOptions.pathParameters = {
            bundleId: bundleId,
        };
        return callOptions;
    }
    /**
     * Write bundle name in configuration
     *
     * LWM2M path: /1028/{bundleId}/4
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @param name input
     * @return
     */
    putName(
    /*
     * Bundle id
     */
    bundleId, 
    /*
     * Name
     */
    name) {
        return this.serviceCallRunner.execute(this.putNameCall(bundleId, name));
    }
    /**
     *
     *
     * LWM2M path: /1028/{bundleId}/4
     *
     * @tapVersion(">=1.0")
     * @param bundleId input
     * @param name input
     * @return call options
     */
    putNameCall(
    /*
     * Bundle id
     */
    bundleId, 
    /*
     * Name
     */
    name) {
        const callOptions = Object.assign({}, this.resources.putName);
        callOptions.body = name;
        callOptions.pathParameters = {
            bundleId: bundleId,
        };
        return callOptions;
    }
}

const _TAP_SERVICE_EXTENSION_BUNDLE_ = extendServiceContainer('bundle', BundleService);

/**
 *   Generated file. Do not edit
 */
const ResourceMetaData = {
    '/bundle/{bundleId}/acl': {
        put: {
            minApiVersion: 1.0,
            configModeRequired: true,
            schema: {
                $ref: './definitions.yaml#/ReadWriteRights',
            },
        },
    },
    '/bundle/{bundleId}/data-log-period': {
        put: {
            minApiVersion: 1.0,
            configModeRequired: true,
            schema: {
                type: 'integer',
                format: 'uint32',
            },
        },
    },
    '/bundle/{bundleId}/data-log-crypto-group-id': {
        put: {
            minApiVersion: 1.0,
            configModeRequired: true,
            schema: {
                type: 'integer',
                format: 'uint16',
            },
        },
    },
    '/bundle/{bundleId}/name': {
        put: {
            minApiVersion: 1.0,
            configModeRequired: true,
            schema: {
                type: 'string',
                maxLength: 16,
                minLength: 1,
            },
        },
    },
};

// import './lib/custom/extension';

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

export { SERVICE_CALLS as BUNDLE_SERVICE_CALLS, ResourceMetaData as BundleResourceMetaData, BundleService, ReadWriteRightsConverter, _TAP_SERVICE_EXTENSION_BUNDLE_, serviceConverters as bundleConverters };
//# sourceMappingURL=iotize-tap-service-impl-bundle.js.map
