"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.trackPurchaseDefaultSubscription = exports.browserTrackPurchaseFields = void 0;
const actions_shared_1 = require("@segment/actions-shared");
const actions_shared_2 = require("@segment/actions-shared");
const actions_shared_3 = require("@segment/actions-shared");
exports.browserTrackPurchaseFields = actions_shared_2.trackPurchaseFields({});
exports.trackPurchaseDefaultSubscription = 'event = "Order Completed"';
const trackPurchasePub = {
    fields: {
        orderId: { name: 'id', convert: actions_shared_3.enjoinString },
        amount: { convert: actions_shared_3.enjoinNumber },
        currency: actions_shared_1.COPY,
        coupon: { name: 'couponCode' },
        attributionId: actions_shared_1.COPY,
        referralCode: actions_shared_1.COPY,
        giftCardCodes: {
            type: 'array'
        },
        products: {
            type: 'array',
            defaultObject: { sku: 'unknown', name: 'unknown', quantity: 1 },
            fields: {
                sku: { convert: actions_shared_3.enjoinString },
                name: actions_shared_1.COPY,
                quantity: { convert: actions_shared_3.enjoinInteger },
                price: { convert: actions_shared_3.enjoinNumber },
                description: actions_shared_1.COPY,
                category: actions_shared_1.COPY,
                url: actions_shared_1.COPY,
                image_url: { name: 'imageUrl' }
            }
        },
        customerId: { name: ['customer', 'id'], convert: actions_shared_3.enjoinString },
        anonymousId: { name: ['customer', 'anonymousId'] },
        email: { name: ['customer', 'email'] },
        isNewCustomer: { name: ['customer', 'isNewCustomer'] },
        loyaltyStatus: { name: ['customer', 'loyaltyStatus'] },
        firstName: { name: ['customer', 'firstName'] },
        lastName: { name: ['customer', 'lastName'] },
        name: { name: ['customer', 'name'] },
        age: { name: ['customer', 'age'], convert: actions_shared_3.enjoinInteger },
        birthday: { name: ['customer', 'birthday'], convert: actions_shared_3.parseDate }
    },
    unmappedFieldObject: actions_shared_1.ROOT,
    finalize: actions_shared_3.removeCustomerIfNoId
};
const action = {
    title: 'Track Purchase',
    description: 'Record when a customer makes a purchase.',
    defaultSubscription: exports.trackPurchaseDefaultSubscription,
    platform: 'web',
    fields: exports.browserTrackPurchaseFields,
    perform: (friendbuyAPI, { payload }) => {
        actions_shared_3.addName(payload);
        const friendbuyPayload = actions_shared_1.mapEvent(trackPurchasePub, payload);
        friendbuyAPI.push(['track', 'purchase', friendbuyPayload, true]);
    }
};
exports.default = action;
//# sourceMappingURL=index.js.map