"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extractSchemaFromEvent = extractSchemaFromEvent;
const AvoSchemaParser_1 = require("./AvoSchemaParser");
function getAppNameFromUrl(url) {
    return url.split('/')[2];
}
function generateBaseBody(event, appVersionPropertyName) {
    const appName = event.appName ?? (event.pageUrl ? getAppNameFromUrl(event.pageUrl) : 'unnamed Segment app');
    let appVersion;
    if (appVersionPropertyName !== undefined && appVersionPropertyName in event.properties) {
        appVersion = event.properties[appVersionPropertyName];
    }
    else {
        appVersion = event.appVersion ?? 'unversioned';
    }
    return {
        appName: appName,
        appVersion: appVersion,
        libVersion: '1.0.0',
        libPlatform: 'Segment',
        messageId: event.messageId,
        createdAt: event.createdAt,
        sessionId: '_'
    };
}
function handleEvent(baseBody, event) {
    const eventBody = {
        ...baseBody,
        type: 'event',
        eventName: event.event,
        eventProperties: AvoSchemaParser_1.AvoSchemaParser.extractSchema(event.properties),
        eventId: null,
        eventHash: null
    };
    return eventBody;
}
function extractSchemaFromEvent(event, appVersionPropertyName) {
    const baseBody = generateBaseBody(event, appVersionPropertyName);
    const eventBody = handleEvent(baseBody, event);
    return eventBody;
}
//# sourceMappingURL=avo.js.map