"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.deleteDocument = deleteDocument;
exports.deleteMe = deleteMe;
exports.getDocuments = getDocuments;
exports.getExportMyData = getExportMyData;
exports.getMyUser = getMyUser;
exports.updateMe = updateMe;
exports.updateProfile = updateProfile;
var _apiClient = _interopRequireDefault(require("../apiClient"));
var _roomStore = require("../../roomStore");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
async function getMyUser(options) {
  const token = options?.token || _roomStore.store.getState().chatSettingStore.user.token || '';
  const endpoint = options?.endpoint || '/users/my';
  const response = await _apiClient.default.get(endpoint, {
    headers: {
      Authorization: token
    }
  });
  if (response?.data?.user) {
    return response.data.user;
  }
  return response.data;
}
function getDocuments(walletAddress) {
  const token = _roomStore.store.getState().chatSettingStore.user.token || '';
  return _apiClient.default.get(`/docs/${walletAddress}`, {
    headers: {
      Authorization: `Bearer ${token}`
    }
  });
}
function getExportMyData() {
  const token = _roomStore.store.getState().chatSettingStore.user.token || '';
  return _apiClient.default.get('/users/exportData', {
    headers: {
      Authorization: token,
      responseType: 'arraybuffer'
    }
  });
}
function deleteDocument(fileId) {
  const token = _roomStore.store.getState().chatSettingStore.user.token || '';
  return _apiClient.default.delete(`/files/${fileId}`, {
    headers: {
      Authorization: token
    }
  });
}
function deleteMe() {
  return _apiClient.default.delete('/users');
}
function updateMe(data) {
  return _apiClient.default.put('/users', data);
}
async function updateProfile(fd) {
  const token = _roomStore.store.getState().chatSettingStore.user.token || '';
  try {
    const response = await _apiClient.default.put('/users', fd, {
      headers: {
        Authorization: token,
        'Content-Type': 'multipart/form-data'
      }
    });
    return response.data;
  } catch (error) {
    throw new Error('Error updating profile');
  }
}
//# sourceMappingURL=user.api.js.map