"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendBillingLogsToApi = sendBillingLogsToApi;
const axios_1 = __importDefault(require("axios"));
const billingConfig = {
    apiUrl: process.env.BILLING_LOG_API_URL || 'https://billing.getthespiderman.com/api/trusys/logs',
};
/**
 * Send billing logs directly to API and return response with totalCost
 */
async function sendBillingLogsToApi(logs) {
    if (!billingConfig.apiUrl) {
        throw new Error('Billing API URL not configured');
    }
    try {
        const response = await axios_1.default.post(billingConfig.apiUrl, {
            logs,
            timestamp: new Date().toISOString(),
            source: 'direct-call',
        }, {
            headers: {
                'Content-Type': 'application/json',
            },
        });
        if ([201, 200].includes(response.status) === false) {
            throw new Error(`API request failed with status: ${response.status}`);
        }
        return response.data;
    }
    catch (error) {
        if (error.response) {
            // Server responded with error status
            throw new Error(`API request failed: ${error.response.status} - ${error.response.data}`);
        }
        else if (error.request) {
            // Request was made but no response received
            throw new Error(`API request failed: No response received - ${error.message}`);
        }
        else {
            // Something else happened
            throw new Error(`API request failed: ${error.message}`);
        }
    }
}
//# sourceMappingURL=sendBillingLogs.js.map