"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.test_event_code = exports.event_id = exports.event_source_url = exports.action_source = exports.event_time = exports.num_items = exports.dataProcessingOptions = exports.validateContents = exports.data_processing_options_state = exports.data_processing_options_country = exports.data_processing_options = exports.contents = exports.content_type = exports.content_name = exports.content_ids = exports.content_category = exports.net_revenue = exports.value = exports.currency = exports.custom_data = void 0;
const actions_core_1 = require("@segment/actions-core");
exports.custom_data = {
    label: 'Custom Data',
    description: 'The custom data object can be used to pass custom properties. See [Facebook documentation](https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data#custom-properties) for more information.',
    type: 'object',
    defaultObjectUI: 'keyvalue'
};
exports.currency = {
    label: 'Currency',
    description: 'The currency for the value specified. Currency must be a valid ISO 4217 three-digit currency code.',
    type: 'string',
    default: {
        '@path': '$.properties.currency'
    }
};
exports.value = {
    label: 'Value',
    description: 'A numeric value associated with this event. This could be a monetary value or a value in some other metric.',
    type: 'number'
};
exports.net_revenue = {
    label: 'Net Revenue',
    description: 'The numeric net revenue value associated with the purchase event.',
    type: 'number'
};
exports.content_category = {
    label: 'Content Category',
    description: 'The category of the content associated with the event.',
    type: 'string'
};
exports.content_ids = {
    label: 'Content IDs',
    description: 'The content IDs associated with the event, such as product SKUs.',
    type: 'string',
    multiple: true
};
exports.content_name = {
    label: 'Content Name',
    description: 'The name of the page or product associated with the event.',
    type: 'string'
};
exports.content_type = {
    label: 'Content Type',
    description: 'The content type should be set to product or product_group. See [Facebook documentation](https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/custom-data) for more information.',
    type: 'string'
};
exports.contents = {
    label: 'Contents',
    description: 'A list of JSON objects that contain the product IDs associated with the event plus information about the products. ID and quantity are required fields.',
    type: 'object',
    multiple: true,
    properties: {
        id: {
            label: 'ID',
            description: 'The product ID of the purchased item.',
            type: 'string'
        },
        quantity: {
            label: 'Quantity',
            description: 'The number of items purchased.',
            type: 'integer'
        },
        item_price: {
            label: 'Item Price',
            description: 'The price of the item.',
            type: 'number'
        },
        delivery_category: {
            label: 'Delivery Category',
            description: 'The type of delivery for a purchase event. Supported values are "in_store", "curbside", and "home_delivery".',
            type: 'string'
        }
    }
};
exports.data_processing_options = {
    label: 'Data Processing Options',
    description: `The Data Processing Options to send to Facebook. If set to true, Segment will send an array to Facebook indicating events should be processed with Limited Data Use (LDU) restrictions. More information can be found in [Facebook’s documentation](https://developers.facebook.com/docs/marketing-apis/data-processing-options).`,
    type: 'boolean'
};
exports.data_processing_options_country = {
    label: 'Data Processing Country',
    description: 'A country that you want to associate to the Data Processing Options. Accepted values are 1, for the United States of America, or 0, to request that Facebook geolocates the event using IP address. This is required if Data Processing Options is set to true. If nothing is provided, Segment will send 0.',
    type: 'number',
    choices: [
        { label: 'Use Facebook’s Geolocation Logic', value: 0 },
        { label: 'United States of America', value: 1 }
    ]
};
exports.data_processing_options_state = {
    label: 'Data Processing State',
    description: 'A state that you want to associate to the Data Processing Options. Accepted values are 1000, for California, or 0, to request that Facebook geolocates the event using IP address. This is required if Data Processing Options is set to true. If nothing is provided, Segment will send 0.',
    type: 'number',
    choices: [
        { label: 'Use Facebook’s Geolocation Logic', value: 0 },
        { label: 'California', value: 1000 },
        { label: 'Colorado', value: 1001 },
        { label: 'Connecticut', value: 1002 },
        { label: 'Florida', value: 1003 },
        { label: 'Oregon', value: 1004 },
        { label: 'Texas', value: 1005 },
        { label: 'Montana', value: 1006 },
        { label: 'Delaware', value: 1007 },
        { label: 'Nebraska', value: 1008 },
        { label: 'New Hampshire', value: 1009 },
        { label: 'New Jersey', value: 1010 }
    ]
};
const validateContents = (contents) => {
    const valid_delivery_categories = ['in_store', 'curbside', 'home_delivery'];
    for (let i = 0; i < contents.length; i++) {
        const item = contents[i];
        if (!item.id) {
            return new actions_core_1.PayloadValidationError(`contents[${i}] must include an 'id' parameter.`);
        }
        if (item.delivery_category && !valid_delivery_categories.includes(item.delivery_category)) {
            return new actions_core_1.PayloadValidationError(`contents[${i}].delivery_category must be one of {in_store, home_delivery, curbside}.`);
        }
    }
    return false;
};
exports.validateContents = validateContents;
const dataProcessingOptions = (data_processing_options, countryOption, stateOption) => {
    if (data_processing_options) {
        const data_options = ['LDU'];
        const country_code = countryOption ? countryOption : 0;
        const state_code = stateOption ? stateOption : 0;
        return [data_options, country_code, state_code];
    }
    return [];
};
exports.dataProcessingOptions = dataProcessingOptions;
exports.num_items = {
    label: 'Number of Items',
    description: 'The number of items when checkout was initiated.',
    type: 'integer'
};
exports.event_time = {
    label: 'Event Time',
    description: 'A Unix timestamp in seconds indicating when the actual event occurred. Facebook will automatically convert ISO 8601 timestamps to Unix.',
    type: 'string',
    default: {
        '@path': '$.timestamp'
    }
};
exports.action_source = {
    label: 'Action Source',
    description: 'This field allows you to specify where your conversions occurred. See [Facebook documentation](https://developers.facebook.com/docs/marketing-api/conversions-api/parameters/server-event) for supported values.',
    type: 'string',
    choices: [
        { label: 'EMAIL', value: 'email' },
        { label: 'WEBSITE', value: 'website' },
        { label: 'APP', value: 'app' },
        { label: 'PHONE CALL', value: 'phone_call' },
        { label: 'CHAT', value: 'chat' },
        { label: 'PHYSICAL STORE', value: 'physical_store' },
        { label: 'SYSTEM GENERATED', value: 'system_generated' },
        { label: 'OTHER', value: 'other' }
    ]
};
exports.event_source_url = {
    label: 'Event Source URL',
    description: 'The browser URL where the event happened. The URL must begin with http:// or https:// and should match the verified domain. This is required if the action source is "website."',
    type: 'string',
    default: {
        '@path': '$.context.page.url'
    }
};
exports.event_id = {
    label: 'Event ID',
    description: 'This ID can be any unique string. Event ID is used to deduplicate events sent by both Facebook Pixel and Conversions API.',
    type: 'string',
    default: {
        '@path': '$.messageId'
    }
};
exports.test_event_code = {
    label: 'Test Event Code',
    type: 'string',
    description: 'Use this field to specify that events should be test events rather than actual traffic. You can find your Test Event Code in your Facebook Events Manager under the "Test events" tab. This property overrides the test event code defined in Settings. You\'ll want to remove your Test Event Code when sending real traffic through this integration.',
    required: false
};
//# sourceMappingURL=fb-capi-properties.js.map