"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendbirdDeskErrorToActivityEvent = exports.isSendbirdDeskError = exports.sendbirdChatErrorToActivityEvent = exports.isSendbirdChatError = void 0;
const axios_1 = require("axios");
const isSendbirdChatError = (error) => {
    var _a;
    if ((0, axios_1.isAxiosError)(error)) {
        const errorData = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
        return 'error' in errorData && 'code' in errorData && 'message' in errorData;
    }
    return false;
};
exports.isSendbirdChatError = isSendbirdChatError;
const sendbirdChatErrorToActivityEvent = (error) => {
    var _a, _b, _c;
    const errorData = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
    const message = `(CODE: ${(_b = errorData === null || errorData === void 0 ? void 0 : errorData.code) !== null && _b !== void 0 ? _b : ''}) ${(_c = errorData === null || errorData === void 0 ? void 0 : errorData.message) !== null && _c !== void 0 ? _c : ''}`;
    return [
        {
            date: new Date().toISOString(),
            text: { en: message },
            error: {
                category: 'SERVER_ERROR',
                message,
            },
        },
    ];
};
exports.sendbirdChatErrorToActivityEvent = sendbirdChatErrorToActivityEvent;
const isSendbirdDeskError = (error) => {
    var _a;
    if ((0, axios_1.isAxiosError)(error)) {
        const errorData = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
        return 'code' in errorData && 'detail' in errorData;
    }
    return false;
};
exports.isSendbirdDeskError = isSendbirdDeskError;
const sendbirdDeskErrorToActivityEvent = (error) => {
    var _a, _b, _c;
    const errorData = (_a = error.response) === null || _a === void 0 ? void 0 : _a.data;
    const message = `(CODE: ${(_b = errorData === null || errorData === void 0 ? void 0 : errorData.code) !== null && _b !== void 0 ? _b : ''}) ${(_c = errorData === null || errorData === void 0 ? void 0 : errorData.detail) !== null && _c !== void 0 ? _c : ''}`;
    return [
        {
            date: new Date().toISOString(),
            text: { en: message },
            error: {
                category: 'SERVER_ERROR',
                message,
            },
        },
    ];
};
exports.sendbirdDeskErrorToActivityEvent = sendbirdDeskErrorToActivityEvent;
//# sourceMappingURL=error.js.map