"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.FieldsSchema = exports.dataPoints = exports.fields = void 0;
const zod_1 = require("zod");
const extensions_core_1 = require("@awell-health/extensions-core");
const types_1 = require("./types");
const types_2 = require("../types");
const validateJsonField_1 = require("../utils/validateJsonField");
const libphonenumber_js_1 = require("libphonenumber-js");
const format_1 = __importDefault(require("date-fns/format"));
const lodash_1 = require("lodash");
exports.fields = {
    broadcastName: {
        id: 'broadcastName',
        label: 'Broadcast Name',
        type: extensions_core_1.FieldType.STRING,
        required: true,
        description: 'The name of the broadcast.',
    },
    broadcastType: {
        id: 'broadcastType',
        label: 'Broadcast Type',
        type: extensions_core_1.FieldType.STRING,
        required: true,
        description: 'The type of broadcast.',
        options: {
            dropdownOptions: Object.values(types_1.BroadcastTypes.enum).map((type) => ({
                label: type,
                value: type,
            })),
        },
    },
    startDate: {
        id: 'startDate',
        label: 'Start Date',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: 'The time the broadcast should start. Will default to start immediately. If provided must be a datetime as ISO 8601 string and time to send the message in UTC',
    },
    maxMessageLength: {
        id: 'maxMessageLength',
        label: 'Max Message Length',
        type: extensions_core_1.FieldType.NUMERIC,
        required: false,
        description: 'The maximum number of seconds the audio message can be. If not set, the value from your voice settings.',
    },
    callerID: {
        id: 'callerID',
        label: 'Caller ID',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: 'Voice messages will appear to be coming from this phone number. If left blank, we will default to the callerID in your voice settings. Must be a valid North American Numbering Plan (NANP) phone number.',
    },
    phoneNumber: {
        id: 'phoneNumber',
        label: 'Phone Number',
        type: extensions_core_1.FieldType.STRING,
        stringType: extensions_core_1.StringType.PHONE,
        required: true,
        description: 'The primary phone number of the recipient in E.164 format',
    },
    checkCallingWindow: {
        id: 'checkCallingWindow',
        label: 'Check Calling Window',
        type: extensions_core_1.FieldType.BOOLEAN,
        required: false,
        description: 'Used for voice messages only and determines whether to enforce or ignore the user`s calling window. Defaults to True.',
    },
    continueOnNextDay: {
        id: 'continueOnNextDay',
        label: 'Continue On Next Day',
        type: extensions_core_1.FieldType.BOOLEAN,
        required: false,
        description: 'Can override the "continue on next day" user setting.',
    },
    transferAndConnect: {
        id: 'transferAndConnect',
        label: 'Transfer and Connect',
        type: extensions_core_1.FieldType.JSON,
        required: false,
        description: 'The settings for transfer & connect broadcasts. Only required for Transfer & Connect type broadcasts.',
    },
    audio: {
        id: 'audio',
        label: 'Audio',
        type: extensions_core_1.FieldType.JSON,
        required: false,
        description: 'The assigned audio message for voice broadcasts. This ID can be found in your Message Library. If left blank you will receive a message recording information in your response.',
    },
    audioVM: {
        id: 'audioVM',
        label: 'Audio VM',
        type: extensions_core_1.FieldType.JSON,
        required: false,
        description: 'This message plays if the contact`s message is left on the recipient`s voicemail.',
    },
    retryTimes: {
        id: 'retryTimes',
        label: 'Retry Times',
        type: extensions_core_1.FieldType.NUMERIC,
        required: false,
        description: 'The number of times a call is retried after busy signal or no answer. Defaults to retry settings in your account.',
    },
    callThrottle: {
        id: 'callThrottle',
        label: 'Call Throttle',
        type: extensions_core_1.FieldType.NUMERIC,
        required: false,
        description: 'The call speed specifies the number of simultaneous calls that can be ongoing at any given time. Defaults to call speed settings in your account.',
    },
};
exports.dataPoints = {
    broadcastId: {
        key: 'broadcastId',
        valueType: 'number',
    },
    broadcastStatus: {
        key: 'broadcastStatus',
        valueType: 'string',
    },
    uriBroadcastDetails: {
        key: 'uriBroadcastDetails',
        valueType: 'string',
    },
    broadcastStatusCategory: {
        key: 'broadcastStatusCategory',
        valueType: 'string',
    },
    broadcastStartDate: {
        key: 'broadcastStartDate',
        valueType: 'string',
    },
};
exports.FieldsSchema = zod_1.z.object({
    broadcastName: zod_1.z.string(),
    broadcastType: types_1.BroadcastTypes,
    startDate: extensions_core_1.DateTimeSchema.optional().transform((date) => {
        if ((0, lodash_1.isNil)(date) || date === '')
            return undefined;
        // format is required: 2/1/2020 1:15PM',
        return (0, format_1.default)(new Date(date), 'M/d/yyyy h:mmaa');
    }),
    maxMessageLength: zod_1.z.number().optional(),
    callerID: zod_1.z.string().optional(),
    phoneNumber: zod_1.z.string().transform((phone) => {
        const parsedNumber = (0, libphonenumber_js_1.parsePhoneNumber)(phone);
        return parsedNumber.format('NATIONAL'); // Returns "(XXX) XXX-XXXX" NANP format
    }),
    checkCallingWindow: zod_1.z.boolean().optional(),
    continueOnNextDay: zod_1.z.boolean().optional(),
    transferAndConnect: zod_1.z
        .optional(zod_1.z.string())
        .transform((0, validateJsonField_1.validateJsonField)(types_2.TransferSchema, 'Missing required transfer details fields. Required fields: transferNumber, transferMessage, transferDigit, transferIntroduction')),
    audio: zod_1.z
        .optional(zod_1.z.string())
        .transform((0, validateJsonField_1.validateJsonField)(types_2.AudioSchema, 'Invalid audio details. Required fields: Uri, AudioID, Name, Description, Favorite, Shared, Length, MessageType, ReadOnly, Created, LastUsed, TextToSpeech, Text, Voice')),
    audioVM: zod_1.z
        .optional(zod_1.z.string())
        .transform((0, validateJsonField_1.validateJsonField)(types_2.AudioSchema, 'Invalid audioVM details. Required fields: Uri, AudioID, Name, Description, Favorite, Shared, Length, MessageType, ReadOnly, Created, LastUsed, TextToSpeech, Text, Voice')),
    retryTimes: zod_1.z.number().optional(),
    callThrottle: zod_1.z.number().optional(),
});
//# sourceMappingURL=config.js.map