"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendEventToAWS = void 0;
const uuid_1 = require("@lukeed/uuid");
const s3_1 = require("../../lib/AWS/s3");
const client_s3_1 = require("@aws-sdk/client-s3");
const NODE_ENV = process.env['NODE_ENV'] || `stage`;
const AWS_REGION = process.env['AWS_REGION'] || `us-west-2`;
const S3_BUCKET_NAME = `integrations-outbound-event-store-${NODE_ENV}-${AWS_REGION}`;
const ACTION_SLUG = `actions-the-trade-desk-crm`;
const sendEventToAWS = async (input) => {
    const uuidValue = (0, uuid_1.v4)();
    const userdataFilePath = `${ACTION_SLUG}/${input.AdvertiserId}/${input.CrmDataId}/${uuidValue}.txt`;
    const metadataFilePath = `${ACTION_SLUG}/${input.AdvertiserId}/${input.CrmDataId}/meta.json`;
    const metadata = {
        TDDAuthToken: input.TTDAuthToken,
        TTDAuthToken: input.TTDAuthToken,
        AdvertiserId: input.AdvertiserId,
        CrmDataId: input.CrmDataId,
        DropOptions: input.DropOptions,
        RequeueCount: 0,
        segmentInternal: {
            audienceId: input.segmentInternal.audienceId || '',
            destinationConfigId: input.segmentInternal.destinationConfigId || '',
            subscriptionId: input.segmentInternal.subscriptionId || ''
        }
    };
    const s3Client = (0, s3_1.getS3Client)('integrationsOutboundController');
    await Promise.all([
        s3Client.send(new client_s3_1.PutObjectCommand({
            Bucket: S3_BUCKET_NAME,
            Key: userdataFilePath,
            Body: input.UsersFormatted,
            ContentType: 'text/csv',
            Metadata: {
                'row-count': `${input.RowCount}`
            }
        })),
        s3Client.send(new client_s3_1.PutObjectCommand({
            Bucket: S3_BUCKET_NAME,
            Key: metadataFilePath,
            Body: JSON.stringify(metadata),
            ContentType: 'application/json'
        }))
    ]);
};
exports.sendEventToAWS = sendEventToAWS;
//# sourceMappingURL=awsClient.js.map