import '../generated/service-container-extension';
import { SinglePacketService } from '../generated/service';
import { SinglePacketError } from './definitions';
import { EncryptedSinglePacketConverter } from './single-packet-converter';
import { SinglePacketStoreLoader } from './single-packet-store-loader';
import { usernameToSenderId } from './util';
/**
 * Load single packet model to store
 * SinglePacket will be encoded to a single packet frame.
 * If credentials parameter is given, it will be encrypted with it and sender id will be filled
 * If no credential is given and SinglePacket.header.encryption is set to true, it will throw an error
 *
 * @param packet
 * @param credentials
 */
SinglePacketService.prototype.createStoreLoader = function (packet, options, credentials) {
    const encoder = EncryptedSinglePacketConverter.createWithBlankKey();
    if (credentials) {
        encoder.setEncryptionOptions(credentials);
        packet.header.encryption = true;
        packet.header.senderId = usernameToSenderId(credentials.username);
    }
    else if (packet.header.encryption) {
        throw SinglePacketError.credentialsRequiredForEncryptedSinglePacket();
    }
    const encodedPacket = encoder.encode(packet);
    return this.createStoreLoaderFromBytes(encodedPacket, options);
};
SinglePacketService.prototype.createStoreLoaderFromBytes = function (data, options) {
    return SinglePacketStoreLoader.createFromBytes(data, this, options);
};
// SinglePacketService.prototype.loadChunksToStore = function (
//     this: SinglePacketService,
//     packets: SinglePacketChunk[]
// ): Observable<any> {
//     return this.createChunksToStoreLoader.asObservable();
// };
// SinglePacketService.prototype.createChunksToStoreLoader = function (
//     this: SinglePacketService,
//     packets: SinglePacketChunk[]
// ): SinglePacketStoreLoader {
//     return SinglePacketStoreLoader.createFromChunks(
//         packets,
//         this
//     );
// };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmUtbG9hZGVyLXNlcnZpY2UtZXh0ZW5zaW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vLi4vc2VydmljZS9pbXBsL3NpbmdsZS1wYWNrZXQvc3JjL2xpYi9jdXN0b20vc3RvcmUtbG9hZGVyLXNlcnZpY2UtZXh0ZW5zaW9uLnRzIl0sIm5hbW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