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

/**
 * Servicio para enviar mensajes por WhatsApp
 */
const whatsappService = {
    /**
     * Enviar factura completa (PDF y XML)
     * @param {Object} data - Datos de la factura
     */
    async sendInvoice({ phone_number, invoice_number, pdf_url, xml_url, customer_name }) {
        try {
            const { data } = await axios.post(
                apiURL('whatsapp/send-invoice'),
                {
                    phone_number,
                    invoice_number,
                    pdf_url,
                    xml_url, // Enviamos ambos links
                    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 Invoice Error:', errorData);
            throw errorData;
        }
    },
};

export default whatsappService;