"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BroadcastInputSchema = exports.FieldsSchema = exports.dataPoints = exports.DeliveryResultType = exports.fields = void 0;
const zod_1 = require("zod");
const extensions_core_1 = require("@awell-health/extensions-core");
const libphonenumber_js_1 = require("libphonenumber-js");
const lodash_1 = require("lodash");
const format_1 = __importDefault(require("date-fns/format"));
exports.fields = {
    broadcastName: {
        id: 'broadcastName',
        label: 'Broadcast Name',
        type: extensions_core_1.FieldType.STRING,
        required: true,
        description: 'The name of the broadcast.',
    },
    phoneNumber: {
        id: 'phoneNumber',
        label: 'Phone Number',
        type: extensions_core_1.FieldType.STRING,
        stringType: extensions_core_1.StringType.PHONE,
        required: false,
        description: 'The primary phone number of the recipient. Must be a valid NANP phone number. If omitted, falls back to the patient mobile phone from their profile.',
    },
    firstName: {
        id: 'firstName',
        label: 'First Name',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: 'The first name of the contact. If omitted, falls back to the patient first name from their profile.',
    },
    lastName: {
        id: 'lastName',
        label: 'Last Name',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: 'The last name of the contact. If omitted, falls back to the patient last name from their profile.',
    },
    notes: {
        id: 'notes',
        label: 'Notes',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: 'Notes about the contact (e.g., "Eligibility form from Awell").',
    },
    integrationData: {
        id: 'integrationData',
        label: 'Integration Data',
        type: extensions_core_1.FieldType.STRING,
        required: false,
        description: 'Extra field for integration information.',
    },
    textMessage: {
        id: 'textMessage',
        label: 'Text Message',
        type: extensions_core_1.FieldType.TEXT,
        required: true,
        description: 'The text of the message for a text type broadcast. The max length is based on the setting in your account.',
    },
    textNumberID: {
        id: 'textNumberID',
        label: 'Text Number ID',
        type: extensions_core_1.FieldType.NUMERIC,
        required: false,
        description: 'The ID of the text number your messages will be sent from. If omitted, the default text number on your account will be used.',
    },
    startDate: {
        id: 'startDate',
        label: 'Start Date',
        type: extensions_core_1.FieldType.DATE,
        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',
    },
    checkCallingWindow: {
        id: 'checkCallingWindow',
        label: 'Check Calling Window',
        type: extensions_core_1.FieldType.BOOLEAN,
        required: false,
        description: 'Whether to enforce the calling window restrictions. Defaults to false.',
    },
};
/**
 * Result types for SMS broadcast creation.
 * - 'sent': Broadcast created successfully, message sent to carrier
 * - 'invalid_number': Phone number is invalid or recipient cannot receive texts (opted out, etc.)
 * - 'failed': Other API errors
 */
exports.DeliveryResultType = {
    SENT: 'sent',
    INVALID_NUMBER: 'invalid_number',
    FAILED: 'failed',
};
exports.dataPoints = {
    /**
     * Whether the SMS was sent successfully.
     * true = message sent to carrier, false = failed (invalid number, opted out, etc.)
     */
    success: {
        key: 'success',
        valueType: 'boolean',
    },
    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',
    },
    /**
     * The result of the SMS broadcast creation.
     * Possible values:
     * - 'sent': Broadcast created, message sent to carrier for delivery
     * - 'invalid_number': Phone number is invalid or recipient cannot receive texts
     * - 'failed': Other API errors
     */
    deliveryResult: {
        key: 'deliveryResult',
        valueType: 'string',
    },
    /**
     * Additional details about the result.
     * Contains the error message from Text-Em-All for failed requests.
     */
    deliveryResultDetails: {
        key: 'deliveryResultDetails',
        valueType: 'string',
    },
};
/** Schema for raw field extraction (no transforms, just type checking) */
exports.FieldsSchema = zod_1.z.object({
    broadcastName: zod_1.z.string(),
    phoneNumber: zod_1.z.string().optional(),
    firstName: zod_1.z.string().optional(),
    lastName: zod_1.z.string().optional(),
    notes: zod_1.z.string().optional(),
    integrationData: zod_1.z.string().optional(),
    textMessage: zod_1.z.string(),
    textNumberID: zod_1.z.number().optional(),
    startDate: extensions_core_1.DateTimeSchema.optional(),
    checkCallingWindow: zod_1.z.boolean().optional().default(false),
});
/**
 * Schema for the final resolved broadcast input — after patient profile
 * fallbacks have been applied. This is where all transforms and
 * required-field checks live so everything is validated in one pass.
 */
exports.BroadcastInputSchema = zod_1.z.object({
    broadcastName: zod_1.z.string(),
    phoneNumber: zod_1.z.string().transform((phone) => {
        const parsed = (0, libphonenumber_js_1.parsePhoneNumber)(phone);
        return parsed.format('NATIONAL'); // "(XXX) XXX-XXXX" NANP format
    }),
    firstName: zod_1.z.string().optional(),
    lastName: zod_1.z.string().optional(),
    notes: zod_1.z.string().optional(),
    integrationData: zod_1.z.string().optional(),
    textMessage: zod_1.z.string(),
    textNumberID: zod_1.z.number().optional(),
    startDate: zod_1.z
        .string()
        .optional()
        .transform((date) => {
        if ((0, lodash_1.isNil)(date) || date === '')
            return undefined;
        // format required by Text-Em-All: '2/1/2020 1:15PM'
        return (0, format_1.default)(new Date(date), 'M/d/yyyy h:mmaa');
    }),
    checkCallingWindow: zod_1.z.boolean(),
});
//# sourceMappingURL=config.js.map