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

/* 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.
 */
var FirmwareState;
(function (FirmwareState) {
    FirmwareState[FirmwareState["NORMAL"] = 1] = "NORMAL";
    FirmwareState[FirmwareState["UPDATING"] = 2] = "UPDATING";
    FirmwareState[FirmwareState["UPDATED"] = 4] = "UPDATED";
})(FirmwareState || (FirmwareState = {}));

/**
 *   Generated file. Do not edit
 */
TapStreamReader.prototype.readCrcCheckBody = function () {
    const model = {};
    model.address = this.readUnsigned(4);
    model.size = this.readUnsigned(4);
    model.crc = this.readUnsigned(4);
    return model;
};
// TapStreamWriter.prototype.write(model: CrcCheckBody) : TapStreamWriter{
//     return this.writeCrcCheckBody(model)
// }
TapStreamWriter.prototype.writeCrcCheckBody = function (model) {
    this.writeUnsigned(model.address, 4);
    this.writeUnsigned(model.size, 4);
    this.writeUnsigned(model.crc, 4);
    return this;
};

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

/**
 *   Generated file. Do not edit
 */
const firmwareState = createEnumConverter(FirmwareState, 1);
const firmwareStateArray = createEnumArrayConverter(FirmwareState, 1);
const crcCheckBody = new CrcCheckBodyConverter();

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

/**
 *   Generated file. Do not edit
 */
const allConverters = Object.assign(Object.assign({}, converters), serviceConverters);
const SERVICE_CALLS = {
    postPackage: {
        method: TapRequestFrame.MethodType.POST,
        pathAlias: '/firmware/package',
        path: '/5//0',
    },
    postUpdate: {
        method: TapRequestFrame.MethodType.POST,
        pathAlias: '/firmware/update',
        path: '/5//2',
    },
    getState: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: '/firmware/state',
        path: '/5//3',
        responseBodyDecoder: allConverters.firmwareState,
    },
    postCrcCheck: {
        method: TapRequestFrame.MethodType.POST,
        pathAlias: '/firmware/crc-check',
        path: '/5//6',
        bodyEncoder: allConverters.crcCheckBody,
    },
};

class FirmwareService extends AbstractService {
    constructor() {
        super(...arguments);
        this.resources = SERVICE_CALLS;
    }
    /**
     * Firmware package
     *
     * LWM2M path: /5//0
     *
     * @deprecated
     * @tapVersion(">=")
     * @return
     */
    postPackage() {
        return this.serviceCallRunner.execute(this.postPackageCall());
    }
    /**
     *
     *
     * LWM2M path: /5//0
     *
     * @deprecated
     * @tapVersion(">=")
     * @return call options
     */
    postPackageCall() {
        const callOptions = Object.assign({}, this.resources.postPackage);
        return callOptions;
    }
    /**
     * Update
     *
     * LWM2M path: /5//2
     *
     * @deprecated
     * @tapVersion(">=")
     * @return
     */
    postUpdate() {
        return this.serviceCallRunner.execute(this.postUpdateCall());
    }
    /**
     *
     *
     * LWM2M path: /5//2
     *
     * @deprecated
     * @tapVersion(">=")
     * @return call options
     */
    postUpdateCall() {
        const callOptions = Object.assign({}, this.resources.postUpdate);
        return callOptions;
    }
    /**
     * Get state
     *
     * LWM2M path: /5//3
     *
     * @deprecated
     * @tapVersion(">=")
     * @return
     */
    getState() {
        return this.serviceCallRunner.execute(this.getStateCall());
    }
    /**
     *
     *
     * LWM2M path: /5//3
     *
     * @deprecated
     * @tapVersion(">=")
     * @return call options
     */
    getStateCall() {
        const callOptions = Object.assign({}, this.resources.getState);
        return callOptions;
    }
    /**
     * Check CRC
     *
     * LWM2M path: /5//6
     *
     * @deprecated
     * @tapVersion(">=")
     * @param data input
     * @return
     */
    postCrcCheck(
    /*
     *
     */
    data) {
        return this.serviceCallRunner.execute(this.postCrcCheckCall(data));
    }
    /**
     *
     *
     * LWM2M path: /5//6
     *
     * @deprecated
     * @tapVersion(">=")
     * @param data input
     * @return call options
     */
    postCrcCheckCall(
    /*
     *
     */
    data) {
        const callOptions = Object.assign({}, this.resources.postCrcCheck);
        callOptions.body = data;
        return callOptions;
    }
}

const _TAP_SERVICE_EXTENSION_FIRMWARE_ = extendServiceContainer('firmware', FirmwareService);

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

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

export { CrcCheckBodyConverter, SERVICE_CALLS as FIRMWARE_SERVICE_CALLS, FirmwareService, FirmwareState, _TAP_SERVICE_EXTENSION_FIRMWARE_, serviceConverters as firmwareConverters };
//# sourceMappingURL=iotize-tap-service-impl-firmware.js.map
