import { apiURL, token } from '@Services/Api';
import axios from 'axios';

/**
 * Servicio para enviar mensajes por WhatsApp
 */
const whatsappService = {
    /**
     * Enviar documento por WhatsApp
     * @param {Object} data - Datos del documento
     * @returns {Promise}
     */
    async sendDocument({ phone_number, document_url, filename, ticket, customer_name }) {
        try {
            const { data } = await axios.post(
                apiURL('whatsapp/send-document'),
                {
                    phone_number,
                    document_url,
                    filename,
                    ticket,
                    customer_name
                },
                {
                    headers: {
                        'Content-Type': 'application/json',
                        'Accept': 'application/json',
                        'Authorization': `Bearer ${token.value}`
                    }
                }
            );
            return data;
        } catch (error) {
            const errorData = error.response?.data?.data || error.response?.data;
            console.error('WhatsApp Error Detail:', errorData);
            throw errorData;
        }
    },

};

export default whatsappService;