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 () {
    const model = {};
    model.username = this.readString(16);
    model.clientNonce = this.readUnsigned(4);
    return model;
};
TapStreamReader.prototype.readScramLoginResponseBody =
    function () {
        const model = {};
        model.serverNonce = this.readUnsigned(4);
        model.salt = this.readBytes(4);
        model.iterationNumber = this.readUnsigned(4);
        return model;
    };
TapStreamReader.prototype.readEncryptedIVRequest =
    function () {
        const model = {};
        model.iv = this.readBytes(16);
        model.request = this.readBytes();
        return model;
    };
TapStreamReader.prototype.readEncryptedIVResponse =
    function () {
        const 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
 */
class ScramLoginParamsConverter {
    encode(model, stream = new TapStreamWriter()) {
        stream.writeScramLoginParams(model);
        return stream.toBytes;
    }
    decode(data) {
        const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readScramLoginParams();
    }
}
class ScramLoginResponseBodyConverter {
    encode(model, stream = new TapStreamWriter()) {
        stream.writeScramLoginResponseBody(model);
        return stream.toBytes;
    }
    decode(data) {
        const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readScramLoginResponseBody();
    }
}
class EncryptedIVRequestConverter {
    encode(model, stream = new TapStreamWriter()) {
        stream.writeEncryptedIVRequest(model);
        return stream.toBytes;
    }
    decode(data) {
        const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readEncryptedIVRequest();
    }
}
class EncryptedIVResponseConverter {
    encode(model, stream = new TapStreamWriter()) {
        stream.writeEncryptedIVResponse(model);
        return stream.toBytes;
    }
    decode(data) {
        const stream = data instanceof TapStreamReader ? data : TapStreamReader.create(data);
        return stream.readEncryptedIVResponse();
    }
}

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

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

/**
 *   Generated file. Do not edit
 */
const allConverters = Object.assign(Object.assign({}, converters), serviceConverters);
const 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',
    },
    stop: {
        method: TapRequestFrame.MethodType.GET,
        pathAlias: '/scram/stop',
        path: '/1024//46',
    },
    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,
    },
};

class ScramService extends AbstractService {
    constructor() {
        super(...arguments);
        this.resources = SERVICE_CALLS;
    }
    /**
     * Initiate scram login process
     *
     * LWM2M path: /1024//40
     *
     * @tapVersion(">=1.0")
     * @param params input
     * @return
     */
    login(
    /*
     *
     */
    params) {
        return this.serviceCallRunner.execute(this.loginCall(params));
    }
    /**
     *
     *
     * LWM2M path: /1024//40
     *
     * @tapVersion(">=1.0")
     * @param params input
     * @return call options
     */
    loginCall(
    /*
     *
     */
    params) {
        const callOptions = Object.assign({}, this.resources.login);
        callOptions.body = params;
        return callOptions;
    }
    /**
     * Scram login proof
     *
     * LWM2M path: /1024//41
     *
     * @tapVersion(">=1.0")
     * @param params input
     * @return
     */
    loginProof(
    /*
     *
     */
    params) {
        return this.serviceCallRunner.execute(this.loginProofCall(params));
    }
    /**
     *
     *
     * LWM2M path: /1024//41
     *
     * @tapVersion(">=1.0")
     * @param params input
     * @return call options
     */
    loginProofCall(
    /*
     *
     */
    params) {
        const callOptions = Object.assign({}, this.resources.loginProof);
        callOptions.body = params;
        return callOptions;
    }
    /**
     * Get scram hash iteration counter
     *
     * LWM2M path: /1024//42
     *
     * @tapVersion(">=1.11")
     * @return
     */
    getHashIteration() {
        return this.serviceCallRunner.execute(this.getHashIterationCall());
    }
    /**
     *
     *
     * LWM2M path: /1024//42
     *
     * @tapVersion(">=1.11")
     * @return call options
     */
    getHashIterationCall() {
        const callOptions = Object.assign({}, this.resources.getHashIteration);
        return callOptions;
    }
    /**
     * Set scram hash iteration counter
     *
     * LWM2M path: /1024//42
     *
     * @tapVersion(">=1.11")
     * @param data input
     * @return
     */
    putHashIteration(
    /*
     *
     */
    data) {
        return this.serviceCallRunner.execute(this.putHashIterationCall(data));
    }
    /**
     *
     *
     * LWM2M path: /1024//42
     *
     * @tapVersion(">=1.11")
     * @param data input
     * @return call options
     */
    putHashIterationCall(
    /*
     *
     */
    data) {
        const callOptions = Object.assign({}, this.resources.putHashIteration);
        callOptions.body = data;
        return callOptions;
    }
    /**
     * Start encrypted communication
     *
     * LWM2M path: /1024//47
     *
     * @tapVersion(">=1.11")
     * @return
     */
    initialize() {
        return this.serviceCallRunner.execute(this.initializeCall());
    }
    /**
     *
     *
     * LWM2M path: /1024//47
     *
     * @tapVersion(">=1.11")
     * @return call options
     */
    initializeCall() {
        const callOptions = Object.assign({}, this.resources.initialize);
        return callOptions;
    }
    /**
     * Stop encrypted communication
     *
     * LWM2M path: /1024//46
     *
     * @tapVersion(">=1.11")
     * @return
     */
    stop() {
        return this.serviceCallRunner.execute(this.stopCall());
    }
    /**
     *
     *
     * LWM2M path: /1024//46
     *
     * @tapVersion(">=1.11")
     * @return call options
     */
    stopCall() {
        const callOptions = Object.assign({}, this.resources.stop);
        return callOptions;
    }
    /**
     * Communication channel
     *
     * LWM2M path: /1024//48
     *
     * @tapVersion(">=1.11")
     * @param data input
     * @return
     */
    send(
    /*
     *
     */
    data) {
        return this.serviceCallRunner.execute(this.sendCall(data));
    }
    /**
     *
     *
     * LWM2M path: /1024//48
     *
     * @tapVersion(">=1.11")
     * @param data input
     * @return call options
     */
    sendCall(
    /*
     *
     */
    data) {
        const callOptions = Object.assign({}, this.resources.send);
        callOptions.body = data;
        return callOptions;
    }
    /**
     * Exchange new Initialization Vectors
     *
     * LWM2M path: /1024//45
     *
     * @tapVersion(">=1.85")
     * @param data input
     * @return
     */
    setInitializationVector(
    /*
     * 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
     */
    setInitializationVectorCall(
    /*
     * 16 bytes initialization vector
     */
    data) {
        const callOptions = Object.assign({}, 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
     */
    sendWithIV(
    /*
     *
     */
    data) {
        return this.serviceCallRunner.execute(this.sendWithIVCall(data));
    }
    /**
     *
     *
     * LWM2M path: /1024//44
     *
     * @tapVersion(">=1.85")
     * @param data input
     * @return call options
     */
    sendWithIVCall(
    /*
     *
     */
    data) {
        const callOptions = Object.assign({}, this.resources.sendWithIV);
        callOptions.body = data;
        return callOptions;
    }
}

const _TAP_SERVICE_EXTENSION_SCRAM_ = extendServiceContainer('scram', ScramService);

/**
 *   Generated file. Do not edit
 */
const ResourceMetaData = {
    '/scram/hash-iteration': {
        put: {
            minApiVersion: 1.11,
            configModeRequired: true,
            schema: {
                type: 'integer',
                format: 'uint16',
                minimum: 0,
                maximum: 65535,
            },
        },
    },
};

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

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

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