"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.analyticsEventsAPI = void 0;
const config_1 = require("../config");
class AnalyticsEventsAPI {
    post(endpoint, data, id) {
        return __awaiter(this, void 0, void 0, function* () {
            try {
                const response = yield fetch(`${config_1.RoomstayGlobalConfig.RoomstayApiUrl}${endpoint}`, {
                    method: 'POST',
                    headers: { 'Content-Type': 'application/json' },
                    body: JSON.stringify(data),
                });
                if (!response.ok) {
                    const errorData = yield response.json().catch(() => ({}));
                    console.error(`[AnalyticsEventsAPI] POST ${endpoint} failed:`, response.status, errorData);
                    return {
                        success: false,
                        id,
                        message: errorData.message || `HTTP ${response.status}`,
                    };
                }
                return {
                    success: true,
                    id,
                };
            }
            catch (error) {
                console.error(`[AnalyticsEventsAPI] POST ${endpoint} error:`, error);
                return {
                    success: false,
                    id,
                    message: error instanceof Error ? error.message : 'Unknown error',
                };
            }
        });
    }
    createSession(data) {
        return this.post('analytics-sessions', data, data.sessionId);
    }
    sendEvent(data) {
        return this.post('analytics-events', data, data.eventId);
    }
}
exports.analyticsEventsAPI = new AnalyticsEventsAPI();
//# sourceMappingURL=AnalyticsEventsAPI.js.map