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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmUtbG9hZGVyLXNlcnZpY2UtZXh0ZW5zaW9uLmpzIiwic291cmNlUm9vdCI6Im5nOi8vQGlvdGl6ZS90YXAvc2VydmljZS9pbXBsL3NpbmdsZS1wYWNrZXQvIiwic291cmNlcyI6WyJsaWIvY3VzdG9tL3N0b3JlLWxvYWRlci1zZXJ2aWNlLWV4dGVuc2lvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIj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