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';

/* eslint-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["LEGACY"] = 0] = "LEGACY";
    FirmwareState[FirmwareState["NORMAL"] = 1] = "NORMAL";
    FirmwareState[FirmwareState["UPDATING"] = 2] = "UPDATING";
    FirmwareState[FirmwareState["UPDATED"] = 4] = "UPDATED";
})(FirmwareState || (FirmwareState = {}));
/* eslint-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 FirmwareUpdateResult;
(function (FirmwareUpdateResult) {
    FirmwareUpdateResult[FirmwareUpdateResult["DEFAULT_VALUE"] = 0] = "DEFAULT_VALUE";
    FirmwareUpdateResult[FirmwareUpdateResult["UPDATE_SUCCESSFUL"] = 1] = "UPDATE_SUCCESSFUL";
    FirmwareUpdateResult[FirmwareUpdateResult["NOT_ENOUGH_MEMORY"] = 2] = "NOT_ENOUGH_MEMORY";
    FirmwareUpdateResult[FirmwareUpdateResult["OUT_OF_MEMORY"] = 4] = "OUT_OF_MEMORY";
    FirmwareUpdateResult[FirmwareUpdateResult["CONNECTION_LOST"] = 8] = "CONNECTION_LOST";
    FirmwareUpdateResult[FirmwareUpdateResult["CRC_CHECK_FAILURE"] = 16] = "CRC_CHECK_FAILURE";
    FirmwareUpdateResult[FirmwareUpdateResult["UNSUPPORTED_PACKAGE_TYPE"] = 32] = "UNSUPPORTED_PACKAGE_TYPE";
    FirmwareUpdateResult[FirmwareUpdateResult["INVALID_URI"] = 64] = "INVALID_URI";
})(FirmwareUpdateResult || (FirmwareUpdateResult = {}));

/**
 *   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 firmwareUpdateResult = createEnumConverter(FirmwareUpdateResult, 1);
const firmwareUpdateResultArray = createEnumArrayConverter(FirmwareUpdateResult, 1);
const crcCheckBody = new CrcCheckBodyConverter();

var serviceConverters = /*#__PURE__*/Object.freeze({
    __proto__: null,
    firmwareState: firmwareState,
    firmwareStateArray: firmwareStateArray,
    firmwareUpdateResult: firmwareUpdateResult,
    firmwareUpdateResultArray: firmwareUpdateResultArray,
    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,
    },
    getUpdateResult: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: '/firmware/update-result',
        path: '/5//5',
        responseBodyDecoder: allConverters.firmwareUpdateResult,
    },
    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 update data
     *
     * LWM2M path: /5//0
     *
     * @tapVersion(">=1.0")
     * @return
     */
    postPackage() {
        return this.serviceCallRunner.execute(this.postPackageCall());
    }
    /**
     *
     *
     * LWM2M path: /5//0
     *
     * @tapVersion(">=1.0")
     * @return call options
     */
    postPackageCall() {
        const callOptions = Object.assign({}, this.resources.postPackage);
        return callOptions;
    }
    /**
     * firmware Update mode
     *
     * LWM2M path: /5//2
     *
     * @tapVersion(">=1.0")
     * @return
     */
    postUpdate() {
        return this.serviceCallRunner.execute(this.postUpdateCall());
    }
    /**
     *
     *
     * LWM2M path: /5//2
     *
     * @tapVersion(">=1.0")
     * @return call options
     */
    postUpdateCall() {
        const callOptions = Object.assign({}, this.resources.postUpdate);
        return callOptions;
    }
    /**
     * Get state
     *
     * LWM2M path: /5//3
     *
     * @tapVersion(">=1.0")
     * @return
     */
    getState() {
        return this.serviceCallRunner.execute(this.getStateCall());
    }
    /**
     *
     *
     * LWM2M path: /5//3
     *
     * @tapVersion(">=1.0")
     * @return call options
     */
    getStateCall() {
        const callOptions = Object.assign({}, this.resources.getState);
        return callOptions;
    }
    /**
     * Get firmware update result
     *
     * LWM2M path: /5//5
     *
     * @tapVersion(">=1.0")
     * @return
     */
    getUpdateResult() {
        return this.serviceCallRunner.execute(this.getUpdateResultCall());
    }
    /**
     *
     *
     * LWM2M path: /5//5
     *
     * @tapVersion(">=1.0")
     * @return call options
     */
    getUpdateResultCall() {
        const callOptions = Object.assign({}, this.resources.getUpdateResult);
        return callOptions;
    }
    /**
     * Check CRC
     *
     * LWM2M path: /5//6
     *
     * @tapVersion(">=1.0")
     * @param data input
     * @return
     */
    postCrcCheck(
    /*
     *
     */
    data) {
        return this.serviceCallRunner.execute(this.postCrcCheckCall(data));
    }
    /**
     *
     *
     * LWM2M path: /5//6
     *
     * @tapVersion(">=1.0")
     * @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);

/**
 *   Generated file. Do not edit
 */
const ResourceMetaData = {};

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

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

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