import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
import axios from "axios";

/**
 * Sample: {
        key: 'lt2nc8vwbsjlfwap84z',
        contentType: 'application/ld+json',
        data: 'eyJAY29udGV4dCI6eyJpeG8iOiJodHRwczovL3czaWQub3JnL2l4by9ucy9wcm90b2NvbC8iLCJAaWQiOiJAdHlwZSIsInR5cGUiOiJAdHlwZSIsIkBwcm90ZWN0ZWQiOnRydWV9LCJ0eXBlIjoiaXhvOmVudGl0eSNwYWdlIiwicGFnZSI6eyJpZCI6IklyQ2NKOGhsOHQiLCJ0eXBlIjoicGFyYWdyYXBoIiwiZGF0YSI6eyJ0ZXh0IjoiVGhlIEltcGFjdCBEQU8gY29vcGVyYXRpdmUgbWFrZXMgb3V0Y29tZXMtYmFzZWQgaW52ZXN0bWVudHMgaW50byBpbm5vdmF0aW9ucywgcHJvamVjdHMgYW5kIHZlbnR1cmVzIHRoYXQgY2FuIGRsZWl2ZXIgSW50ZXJuZXQgb2YgSW1wYWN0IHNvbHV0aW9ucy4gTWVtYmVycyBvZiB0aGUgREFPIGFyZSBwaW9uZWVyaW5nIGlubm92YXRvcnMsIGludmVzdG9ycywgYnVpbGRlcnMsIGFuZCBpbXBsZW1lbnRvcnMgd2hvIGNvbnRyaWJ1dGUgY2FwaXRhbCwgd29yaywgb3Blbi1zb3VyY2Ugc29mdHdhcmUsIGFuZCBtYXJrZXQgYWNjZXNzIG9wcG9ydHVuaXRpZXMuIFRoZSBEQU8gdHJlYXN1cnkgcHJvdmlkZXMgZmluYW5jaW5nIGZvciB0aGUgZWNvc3lzdGVtIGJ5IGdyb3dpbmcgYSBwb3J0Zm9saW8gb2YgYXNzZXRzIGFuZCBieSBnZW5lcmF0aW5nIHJldmVudWVzIGZyb20gaXRzIGludmVzdG1lbnRzLiBUaGUgREFPIFRva2VucyByZXByZXNlbnQgZWFjaCBtZW1iZXIncyBwYXJ0aWNpcGF0aW9uIHNoYXJlIGluIHRoZSB0cmVhc3VyeSB0aGF0IGNhbiBiZSBleGNoYW5nZWQgYWZ0ZXIgdGhlIERBTyBicmVha3MgZXZlbi4gTW9yZSByZWNlbnQgaW52ZXN0b3JzIHJlY2l2ZSBhIGxpcXVpZGF0aW9uIHByZWZlcmVuY2UuIn19fQ==',
        url: 'https://devnet-cellnode.ixo.earth/public/lt2nc8vwbsjlfwap84z'
      }
 */

/**
 * Sample: {
        cid: 'bafkreieevelc4vmpo6p2lsqu2zgiuc3xatxuzoquwtvqea6zabufbxmwiu',
        name: 'atJywpxoUyHx',
        ipfs: 'bafkreieevelc4vmpo6p2lsqu2zgiuc3xatxuzoquwtvqea6zabufbxmwiu.ipfs.w3s.link',
        url: 'https://bafkreieevelc4vmpo6p2lsqu2zgiuc3xatxuzoquwtvqea6zabufbxmwiu.ipfs.w3s.link'
      }
 */

export const cellNodeChainMapping = {
  mainnet: "https://cellnode.ixo.world",
  testnet: "https://cellnode-pandora.ixo.earth",
  devnet: "https://devnet-cellnode.ixo.earth"
};
export const getPublicDoc = async (cid, cellnodeUrl, chainNetwork = "mainnet") => {
  const baseUrl = cellnodeUrl || cellNodeChainMapping[chainNetwork];
  const url = `${baseUrl}/public/${cid}`;
  const response = await axios.get(url);
  return response.data;
};
export const uploadPublicDoc = async (contentType, data, cellnodeUrl, chainNetwork = "mainnet") => {
  const baseUrl = cellnodeUrl || cellNodeChainMapping[chainNetwork];
  const url = `${baseUrl}/public/createpublic`;
  const response = await axios.post(url, {
    contentType,
    data
  });
  return _objectSpread(_objectSpread({}, response.data), {}, {
    url: `${baseUrl}/public/${response.data.key}`
  });
};
export const getWeb3Doc = async (cid, cellnodeUrl, chainNetwork = "mainnet") => {
  const baseUrl = cellnodeUrl || cellNodeChainMapping[chainNetwork];
  const url = `${baseUrl}/storage/retrieve/${cid}`;
  const response = await axios.get(url);
  return response.data;
};
export const uploadWeb3Doc = async (name, contentType, data, cellnodeUrl, chainNetwork = "mainnet") => {
  const baseUrl = cellnodeUrl || cellNodeChainMapping[chainNetwork];
  const url = `${baseUrl}/storage/store`;
  const response = await axios.post(url, {
    name,
    contentType,
    data
  });
  return _objectSpread(_objectSpread({}, response.data), {}, {
    url: `https://${response.data.ipfs}`
  });
};