"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const actions_core_1 = require("@segment/actions-core");
const reportWebEvent_1 = __importDefault(require("./reportWebEvent"));
const 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)(reportWebEvent_1.default.fields),
    contents: {
        '@arrayPath': [
            '$.properties',
            {
                ...productProperties
            }
        ]
    }
};
const multiProductContents = {
    ...(0, actions_core_1.defaultValues)(reportWebEvent_1.default.fields),
    contents: {
        '@arrayPath': [
            '$.properties.products',
            {
                ...productProperties
            }
        ]
    }
};
const destination = {
    name: 'Tiktok Conversions',
    slug: 'tiktok-conversions',
    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
            },
            pixelCode: {
                label: 'Pixel Code',
                type: 'string',
                description: 'Your TikTok Pixel 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: (request, { settings }) => {
            return request('https://business-api.tiktok.com/open_api/v1.3/pixel/track/', {
                method: 'post',
                json: {
                    pixel_code: settings.pixelCode,
                    event: 'Test Event',
                    timestamp: '',
                    context: {}
                }
            });
        }
    },
    extendRequest({ settings }) {
        return {
            headers: {
                'Access-Token': settings.accessToken,
                'Content-Type': 'application/json'
            }
        };
    },
    presets: [
        {
            name: 'Complete Payment',
            subscribe: 'event = "Order Completed"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...multiProductContents,
                event: 'CompletePayment'
            },
            type: 'automatic'
        },
        {
            name: 'Contact',
            subscribe: 'event = "Callback Started"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(reportWebEvent_1.default.fields),
                event: 'Contact'
            },
            type: 'automatic'
        },
        {
            name: 'Subscribe',
            subscribe: 'event = "Subscription Created"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(reportWebEvent_1.default.fields),
                event: 'Subscribe'
            },
            type: 'automatic'
        },
        {
            name: 'Submit Form',
            subscribe: 'event = "Form Submitted"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(reportWebEvent_1.default.fields),
                event: 'SubmitForm'
            },
            type: 'automatic'
        },
        {
            name: 'Page View',
            subscribe: 'type="page"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...multiProductContents,
                event: 'PageView'
            },
            type: 'automatic'
        },
        {
            name: 'View Content',
            subscribe: 'event = "Product Viewed"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...singleProductContents,
                event: 'ViewContent'
            },
            type: 'automatic'
        },
        {
            name: 'Click Button',
            subscribe: 'event = "Product Clicked"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...singleProductContents,
                event: 'ClickButton'
            },
            type: 'automatic'
        },
        {
            name: 'Search',
            subscribe: 'event = "Products Searched"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...singleProductContents,
                event: 'Search'
            },
            type: 'automatic'
        },
        {
            name: 'Add to Wishlist',
            subscribe: 'event = "Product Added to Wishlist"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...singleProductContents,
                event: 'AddToWishlist'
            },
            type: 'automatic'
        },
        {
            name: 'Add to Cart',
            subscribe: 'event = "Product Added"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...singleProductContents,
                event: 'AddToCart'
            },
            type: 'automatic'
        },
        {
            name: 'Initiate Checkout',
            subscribe: 'event = "Checkout Started"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...multiProductContents,
                event: 'InitiateCheckout'
            },
            type: 'automatic'
        },
        {
            name: 'Add Payment Info',
            subscribe: 'event = "Payment Info Entered"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...multiProductContents,
                event: 'AddPaymentInfo'
            },
            type: 'automatic'
        },
        {
            name: 'Place an Order',
            subscribe: 'event = "Order Placed"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...multiProductContents,
                event: 'PlaceAnOrder'
            },
            type: 'automatic'
        },
        {
            name: 'Download',
            subscribe: 'event = "Download Link Clicked"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(reportWebEvent_1.default.fields),
                event: 'Download'
            },
            type: 'automatic'
        },
        {
            name: 'Complete Registration',
            subscribe: 'event = "Signed Up"',
            partnerAction: 'reportWebEvent',
            mapping: {
                ...(0, actions_core_1.defaultValues)(reportWebEvent_1.default.fields),
                event: 'CompleteRegistration'
            },
            type: 'automatic'
        }
    ],
    actions: {
        reportWebEvent: reportWebEvent_1.default
    }
};
exports.default = destination;
//# sourceMappingURL=index.js.map