"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.normalizationFunctions = exports.segmentSchemaKeyToArrayIndex = exports.SEGMENT_SCHEMA_PROPERTIES = exports.SCHEMA_PROPERTIES = exports.batch_size = exports.enable_batching = exports.adAccountId = void 0;
const constants_1 = require("./constants");
exports.adAccountId = {
    type: 'string',
    label: 'Advertiser Account ID',
    description: 'Your advertiser account id. Read [more](https://www.facebook.com/business/help/1492627900875762).',
    required: true
};
exports.enable_batching = {
    label: 'Enable Batching',
    description: 'Enable batching of requests.',
    type: 'boolean',
    default: true,
    unsafe_hidden: true,
    required: true
};
exports.batch_size = {
    label: 'Batch Size',
    description: 'Maximum number of events to include in each batch. Actual batch sizes may be lower.',
    type: 'number',
    default: 10000,
    unsafe_hidden: true,
    required: true
};
exports.SCHEMA_PROPERTIES = [
    'EXTERN_ID',
    'EMAIL',
    'PHONE',
    'GEN',
    'DOBY',
    'DOBM',
    'DOBD',
    'LN',
    'FN',
    'FI',
    'CT',
    'ST',
    'ZIP',
    'MADID',
    'COUNTRY'
];
exports.SEGMENT_SCHEMA_PROPERTIES = [
    'externalId',
    'email',
    'phone',
    'gender',
    'year',
    'month',
    'day',
    'last',
    'first',
    'firstInitial',
    'city',
    'state',
    'zip',
    'mobileAdId',
    'country'
];
exports.segmentSchemaKeyToArrayIndex = new Map(exports.SEGMENT_SCHEMA_PROPERTIES.map((property, index) => [property, index]));
const normalizePhone = (value) => {
    const removedNonNumveric = value.replace(/\D/g, '');
    return removedNonNumveric.replace(/^0+/, '');
};
const normalizeGender = (value) => {
    const lowerCaseValue = value.toLowerCase().trim();
    if (['male', 'boy', 'm'].includes(lowerCaseValue))
        return 'm';
    if (['female', 'woman', 'girl', 'f'].includes(lowerCaseValue))
        return 'f';
    return value;
};
const normalizeMonth = (value) => {
    const normalizedValue = value.replace(/\s/g, '').trim();
    if (normalizedValue.length === 2 && typeof Number(normalizedValue) === 'number') {
        return normalizedValue;
    }
    const lowerCaseValue = value.trim().toLowerCase();
    const months = [
        'january',
        'february',
        'march',
        'april',
        'may',
        'june',
        'july',
        'august',
        'september',
        'october',
        'november',
        'december'
    ];
    const monthIndex = months.indexOf(lowerCaseValue);
    if (monthIndex === -1) {
        return value;
    }
    if (monthIndex < 9) {
        return `0${monthIndex + 1}`;
    }
    return `${monthIndex + 1}`;
};
const normalizeName = (value) => {
    return value.trim().toLowerCase().replace(/\p{P}/gu, '');
};
const normalizeCity = (value) => {
    return value
        .trim()
        .replace(/[\s\W_]/g, '')
        .toLowerCase();
};
const normalizeState = (value) => {
    if (constants_1.US_STATE_CODES.has(value.toLowerCase().trim())) {
        return constants_1.US_STATE_CODES.get(value.toLowerCase().trim());
    }
    return value
        .trim()
        .replace(/[\s\W_]/g, '')
        .toLowerCase();
};
const normalizeZip = (value) => {
    if (value.includes('-')) {
        return value.split('-')[0];
    }
    return value.trim().replace(/\s/g, '').toLowerCase();
};
const normalizeCountry = (value) => {
    return value
        .trim()
        .replace(/[\s\W_]/g, '')
        .toLowerCase();
};
exports.normalizationFunctions = new Map([
    ['email', (value) => value.trim().toLowerCase()],
    ['phone', normalizePhone],
    ['gender', normalizeGender],
    ['year', (value) => value.trim()],
    ['month', normalizeMonth],
    ['day', (value) => value.trim()],
    ['last', normalizeName],
    ['first', normalizeName],
    ['firstInitial', (value) => value.trim().toLowerCase()],
    ['city', normalizeCity],
    ['state', normalizeState],
    ['zip', normalizeZip],
    ['country', normalizeCountry]
]);
//# sourceMappingURL=fbca-properties.js.map