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.readScramLoginParams = function () {
    var model = {};
    model.username = this.readString(16);
    model.clientNonce = this.readUnsigned(4);
    return model;
};
TapStreamReader.prototype.readScramLoginResponseBody = function () {
    var model = {};
    model.serverNonce = this.readUnsigned(4);
    model.salt = this.readBytes(4);
    model.iterationNumber = this.readUnsigned(4);
    return model;
};
TapStreamReader.prototype.readEncryptedIVRequest = function () {
    var model = {};
    model.iv = this.readBytes(16);
    model.request = this.readBytes();
    return model;
};
TapStreamReader.prototype.readEncryptedIVResponse = function () {
    var model = {};
    model.iv = this.readBytes(16);
    model.response = this.readBytes();
    return model;
};
// TapStreamWriter.prototype.write(model: ScramLoginParams) : TapStreamWriter{
//     return this.writeScramLoginParams(model)
// }
TapStreamWriter.prototype.writeScramLoginParams = function (model) {
    this.writeString(model.username, 16);
    this.writeUnsigned(model.clientNonce, 4);
    return this;
};
// TapStreamWriter.prototype.write(model: ScramLoginResponseBody) : TapStreamWriter{
//     return this.writeScramLoginResponseBody(model)
// }
TapStreamWriter.prototype.writeScramLoginResponseBody = function (model) {
    this.writeUnsigned(model.serverNonce, 4);
    this.writeBytes(model.salt, 4);
    this.writeUnsigned(model.iterationNumber, 4);
    return this;
};
// TapStreamWriter.prototype.write(model: EncryptedIVRequest) : TapStreamWriter{
//     return this.writeEncryptedIVRequest(model)
// }
TapStreamWriter.prototype.writeEncryptedIVRequest = function (model) {
    this.writeBytes(model.iv, 16);
    this.writeBytes(model.request);
    return this;
};
// TapStreamWriter.prototype.write(model: EncryptedIVResponse) : TapStreamWriter{
//     return this.writeEncryptedIVResponse(model)
// }
TapStreamWriter.prototype.writeEncryptedIVResponse = function (model) {
    this.writeBytes(model.iv, 16);
    this.writeBytes(model.response);
    return this;
};

/**
 *   Generated file. Do not edit
 */
var ScramLoginParamsConverter = /** @class */ (function () {
    function ScramLoginParamsConverter() {
    }
    ScramLoginParamsConverter.prototype.encode = function (model, stream) {
        if (stream === void 0) { stream = new TapStreamWriter(); }
        stream.writeScramLoginParams(model);
        return stream.toBytes;
    };
    ScramLoginParamsConverter.prototype.decode = function (data) {
        var stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readScramLoginParams();
    };
    return ScramLoginParamsConverter;
}());
var ScramLoginResponseBodyConverter = /** @class */ (function () {
    function ScramLoginResponseBodyConverter() {
    }
    ScramLoginResponseBodyConverter.prototype.encode = function (model, stream) {
        if (stream === void 0) { stream = new TapStreamWriter(); }
        stream.writeScramLoginResponseBody(model);
        return stream.toBytes;
    };
    ScramLoginResponseBodyConverter.prototype.decode = function (data) {
        var stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readScramLoginResponseBody();
    };
    return ScramLoginResponseBodyConverter;
}());
var EncryptedIVRequestConverter = /** @class */ (function () {
    function EncryptedIVRequestConverter() {
    }
    EncryptedIVRequestConverter.prototype.encode = function (model, stream) {
        if (stream === void 0) { stream = new TapStreamWriter(); }
        stream.writeEncryptedIVRequest(model);
        return stream.toBytes;
    };
    EncryptedIVRequestConverter.prototype.decode = function (data) {
        var stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readEncryptedIVRequest();
    };
    return EncryptedIVRequestConverter;
}());
var EncryptedIVResponseConverter = /** @class */ (function () {
    function EncryptedIVResponseConverter() {
    }
    EncryptedIVResponseConverter.prototype.encode = function (model, stream) {
        if (stream === void 0) { stream = new TapStreamWriter(); }
        stream.writeEncryptedIVResponse(model);
        return stream.toBytes;
    };
    EncryptedIVResponseConverter.prototype.decode = function (data) {
        var stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readEncryptedIVResponse();
    };
    return EncryptedIVResponseConverter;
}());

/**
 *   Generated file. Do not edit
 */
var scramLoginParams = new ScramLoginParamsConverter();
var scramLoginResponseBody = new ScramLoginResponseBodyConverter();
var encryptedIVRequest = new EncryptedIVRequestConverter();
var encryptedIVResponse = new EncryptedIVResponseConverter();

var serviceConverters = /*#__PURE__*/Object.freeze({
    __proto__: null,
    scramLoginParams: scramLoginParams,
    scramLoginResponseBody: scramLoginResponseBody,
    encryptedIVRequest: encryptedIVRequest,
    encryptedIVResponse: encryptedIVResponse
});

/**
 *   Generated file. Do not edit
 */
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var allConverters = __assign(__assign({}, converters), serviceConverters);
var SERVICE_CALLS = {
    login: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/scram/login",
        path: "/1024//40",
        responseBodyDecoder: allConverters.scramLoginResponseBody,
        bodyEncoder: allConverters.scramLoginParams
    },
    loginProof: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/scram/login-proof",
        path: "/1024//41"
    },
    getHashIteration: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/scram/hash-iteration",
        path: "/1024//42",
        responseBodyDecoder: allConverters.uint32
    },
    putHashIteration: {
        method: TapRequestFrame.MethodType.PUT,
        pathAlias: "/scram/hash-iteration",
        path: "/1024//42",
        bodyEncoder: allConverters.uint16
    },
    initialize: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/scram/initialize",
        path: "/1024//47"
    },
    send: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/scram/com-send-receive",
        path: "/1024//48"
    },
    setInitializationVector: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/scram/initialization-vector",
        path: "/1024//45"
    },
    sendWithIV: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: "/scram/send-with-iv",
        path: "/1024//44",
        responseBodyDecoder: allConverters.encryptedIVResponse,
        bodyEncoder: allConverters.encryptedIVRequest
    }
};

var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __assign$1 = (this && this.__assign) || function () {
    __assign$1 = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign$1.apply(this, arguments);
};
var ScramService = /** @class */ (function (_super) {
    __extends(ScramService, _super);
    function ScramService() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.resources = SERVICE_CALLS;
        return _this;
    }
    /**
     * First command to initiate scram login, for client to send login and nonce to IoTize, and IoTize to return user salt, user iteration counter (j) and combined nonce
     *
     * LWM2M path: /1024//40
     *
     * @tapVersion(">=")
     * @param params input
     * @return
     */
    ScramService.prototype.login = function (
    /*
     *
     */
    params) {
        return this.serviceCallRunner.execute(this.loginCall(params));
    };
    /**
     *
     *
     * LWM2M path: /1024//40
     *
     * @tapVersion(">=")
     * @param params input
     * @return call options
     */
    ScramService.prototype.loginCall = function (
    /*
     *
     */
    params) {
        var callOptions = __assign$1({}, this.resources.login);
        callOptions.body = params;
        return callOptions;
    };
    /**
     * Scram login proof
     *
     * LWM2M path: /1024//41
     *
     * @tapVersion(">=")
     * @param params input
     * @return
     */
    ScramService.prototype.loginProof = function (
    /*
     *
     */
    params) {
        return this.serviceCallRunner.execute(this.loginProofCall(params));
    };
    /**
     *
     *
     * LWM2M path: /1024//41
     *
     * @tapVersion(">=")
     * @param params input
     * @return call options
     */
    ScramService.prototype.loginProofCall = function (
    /*
     *
     */
    params) {
        var callOptions = __assign$1({}, this.resources.loginProof);
        callOptions.body = params;
        return callOptions;
    };
    /**
     * Get scram hash iteration counter
     *
     * LWM2M path: /1024//42
     *
     * @tapVersion(">=1.11")
     * @return
     */
    ScramService.prototype.getHashIteration = function () {
        return this.serviceCallRunner.execute(this.getHashIterationCall());
    };
    /**
     *
     *
     * LWM2M path: /1024//42
     *
     * @tapVersion(">=1.11")
     * @return call options
     */
    ScramService.prototype.getHashIterationCall = function () {
        var callOptions = __assign$1({}, this.resources.getHashIteration);
        return callOptions;
    };
    /**
     * Set scram hash iteration counter
     *
     * LWM2M path: /1024//42
     *
     * @tapVersion(">=1.11")
     * @param data input
     * @return
     */
    ScramService.prototype.putHashIteration = function (
    /*
     *
     */
    data) {
        return this.serviceCallRunner.execute(this.putHashIterationCall(data));
    };
    /**
     *
     *
     * LWM2M path: /1024//42
     *
     * @tapVersion(">=1.11")
     * @param data input
     * @return call options
     */
    ScramService.prototype.putHashIterationCall = function (
    /*
     *
     */
    data) {
        var callOptions = __assign$1({}, this.resources.putHashIteration);
        callOptions.body = data;
        return callOptions;
    };
    /**
     * Start scram communication
     *
     * LWM2M path: /1024//47
     *
     * @tapVersion(">=1.11")
     * @return
     */
    ScramService.prototype.initialize = function () {
        return this.serviceCallRunner.execute(this.initializeCall());
    };
    /**
     *
     *
     * LWM2M path: /1024//47
     *
     * @tapVersion(">=1.11")
     * @return call options
     */
    ScramService.prototype.initializeCall = function () {
        var callOptions = __assign$1({}, this.resources.initialize);
        return callOptions;
    };
    /**
     * Communication channel
     *
     * LWM2M path: /1024//48
     *
     * @tapVersion(">=1.11")
     * @param data input
     * @return
     */
    ScramService.prototype.send = function (
    /*
     *
     */
    data) {
        return this.serviceCallRunner.execute(this.sendCall(data));
    };
    /**
     *
     *
     * LWM2M path: /1024//48
     *
     * @tapVersion(">=1.11")
     * @param data input
     * @return call options
     */
    ScramService.prototype.sendCall = function (
    /*
     *
     */
    data) {
        var callOptions = __assign$1({}, this.resources.send);
        callOptions.body = data;
        return callOptions;
    };
    /**
     * Give encryption initialization vector to the Tap. The device returns its own initialization vector
     *
     * LWM2M path: /1024//45
     *
     * @tapVersion(">=1.85")
     * @param data input
     * @return
     */
    ScramService.prototype.setInitializationVector = function (
    /*
     * 16 bytes initialization vector
     */
    data) {
        return this.serviceCallRunner.execute(this.setInitializationVectorCall(data));
    };
    /**
     *
     *
     * LWM2M path: /1024//45
     *
     * @tapVersion(">=1.85")
     * @param data input
     * @return call options
     */
    ScramService.prototype.setInitializationVectorCall = function (
    /*
     * 16 bytes initialization vector
     */
    data) {
        var callOptions = __assign$1({}, this.resources.setInitializationVector);
        callOptions.body = data;
        return callOptions;
    };
    /**
     * Communication channel with encryption initialization vectory
     *
     * LWM2M path: /1024//44
     *
     * @tapVersion(">=1.85")
     * @param data input
     * @return
     */
    ScramService.prototype.sendWithIV = function (
    /*
     *
     */
    data) {
        return this.serviceCallRunner.execute(this.sendWithIVCall(data));
    };
    /**
     *
     *
     * LWM2M path: /1024//44
     *
     * @tapVersion(">=1.85")
     * @param data input
     * @return call options
     */
    ScramService.prototype.sendWithIVCall = function (
    /*
     *
     */
    data) {
        var callOptions = __assign$1({}, this.resources.sendWithIV);
        callOptions.body = data;
        return callOptions;
    };
    return ScramService;
}(AbstractService));

var _TAP_SERVICE_EXTENSION_SCRAM_ = extendServiceContainer("scram", ScramService);

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

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

export { EncryptedIVRequestConverter, EncryptedIVResponseConverter, SERVICE_CALLS as SCRAM_SERVICE_CALLS, ScramLoginParamsConverter, ScramLoginResponseBodyConverter, ScramService, _TAP_SERVICE_EXTENSION_SCRAM_, serviceConverters as scramConverters };
//# sourceMappingURL=iotize-tap-service-impl-scram.js.map
