"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.productProperties = void 0;
const actions_core_1 = require("@segment/actions-core");
const reportAppEvent_1 = __importDefault(require("./reportAppEvent"));
const common_fields_1 = require("./reportAppEvent/fields/common_fields");
exports.productProperties = {
    price: {
        '@path': '$.price'
    },
    quantity: {
        '@path': '$.quantity'
    },
    content_category: {
        '@path': '$.category'
    },
    content_id: {
        '@path': '$.product_id'
    },
    content_name: {
        '@path': '$.name'
    },
    brand: {
        '@path': '$.brand'
    }
};
const singleProductContents = {
    ...(0, actions_core_1.defaultValues)(reportAppEvent_1.default.fields),
    contents: {
        '@arrayPath': [
            '$.properties',
            {
                ...exports.productProperties
            }
        ]
    }
};
const multiProductContents = {
    ...(0, actions_core_1.defaultValues)(reportAppEvent_1.default.fields),
    contents: {
        '@arrayPath': [
            '$.properties.products',
            {
                ...exports.productProperties
            }
        ]
    }
};
const destination = {
    name: 'TikTok App Events',
    slug: 'tiktok-app-events',
    mode: 'cloud',
    authentication: {
        scheme: 'custom',
        fields: {
            accessToken: {
                label: 'Access Token',
                description: 'Your TikTok Access Token. Please see TikTok’s [Events API documentation](https://ads.tiktok.com/marketing_api/docs?id=1701890979375106) for information on how to generate an access token via the TikTok Ads Manager or API.',
                type: 'password',
                required: true
            },
            appID: {
                label: 'TikTok App ID',
                type: 'string',
                description: 'Your TikTok App ID. Please see TikTok’s [Events API documentation](https://ads.tiktok.com/marketing_api/docs?id=1701890979375106) for information on how to find this value.',
                required: true
            }
        },
        testAuthentication: (_) => {
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                'Access-Token': settings.accessToken,
                'Content-Type': 'application/json'
            }
        };
    },
    presets: common_fields_1.STANDARD_EVENTS.map(({ segmentEventName, productMappingType, ttEventName, description }) => ({
        type: 'automatic',
        partnerAction: 'reportAppEvent',
        name: description,
        subscribe: `event = "${segmentEventName}"`,
        mapping: {
            ...(0, actions_core_1.defaultValues)(reportAppEvent_1.default.fields),
            event: ttEventName,
            ...(productMappingType === common_fields_1.PRODUCT_MAPPING_TYPE.SINGLE
                ? singleProductContents
                : productMappingType === common_fields_1.PRODUCT_MAPPING_TYPE.MULTIPLE
                    ? multiProductContents
                    : {})
        }
    })),
    actions: {
        reportAppEvent: reportAppEvent_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map