/**
 * WhatsApp Integration Types
 *
 * Types for WhatsApp integration via Baileys (WhatsApp Web multi-device protocol),
 * enabling mobile communication with the Crewly orchestrator.
 *
 * @module types/whatsapp
 */
import { WHATSAPP_CONSTANTS } from '../constants.js';
/**
 * Check if a contact is allowed to interact with the bot
 *
 * @param from - Sender JID or phone number
 * @param config - WhatsApp configuration with allowed contacts
 * @returns True if contact is allowed to interact
 */
export function isContactAllowed(from, config) {
    if (!config.allowedContacts || config.allowedContacts.length === 0) {
        return true; // No restrictions
    }
    // Strip the @s.whatsapp.net suffix and + prefix for exact comparison.
    // WhatsApp JIDs use full international numbers without + (e.g., 11234567890@s.whatsapp.net).
    const normalizedFrom = from
        .replace(WHATSAPP_CONSTANTS.JID_SUFFIX_PATTERN, '')
        .replace(WHATSAPP_CONSTANTS.PHONE_PREFIX_PATTERN, '');
    return config.allowedContacts.some((contact) => {
        const normalizedContact = contact
            .replace(WHATSAPP_CONSTANTS.PHONE_PREFIX_PATTERN, '')
            .replace(WHATSAPP_CONSTANTS.JID_SUFFIX_PATTERN, '');
        return normalizedFrom === normalizedContact;
    });
}
//# sourceMappingURL=whatsapp.types.js.map