"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.waitFor = exports.mocks = exports.mockGenerator = exports.mockContext = exports.mockByUrl = exports.fakeResponse = exports.fakeFactory = void 0;
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _linkProvider = require("@atlaskit/link-provider");
function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2.default)(o), (0, _possibleConstructorReturn2.default)(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2.default)(t).constructor) : o.apply(t, e)); }
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
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) { (0, _defineProperty2.default)(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; }
var mockContext = exports.mockContext = {
  '@vocab': 'https://www.w3.org/ns/activitystreams#',
  atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
  schema: 'http://schema.org/'
};
var mockGenerator = exports.mockGenerator = {
  '@type': 'Application',
  '@id': 'https://www.atlassian.com/#Jira',
  name: 'Jira'
};
var mockByUrl = exports.mockByUrl = function mockByUrl(url) {
  return {
    meta: {
      visibility: 'public',
      access: 'granted',
      auth: [],
      definitionId: 'd1',
      key: 'object-provider',
      resourceType: 'object-resource',
      subproduct: 'object-subproduct',
      product: 'object-product'
    },
    data: {
      '@context': {
        '@vocab': 'https://www.w3.org/ns/activitystreams#',
        atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
        schema: 'http://schema.org/'
      },
      '@type': 'Object',
      name: url,
      summary: 'Here is your serving of cheese: 🧀',
      'schema:potentialAction': {
        '@id': 'comment',
        '@type': 'CommentAction',
        identifier: 'object-provider',
        name: 'Comment'
      },
      preview: {
        href: 'https://www.ilovecheese.com'
      },
      url: url
    }
  };
};
var errorResponseData = {
  '@context': {
    '@vocab': 'https://www.w3.org/ns/activitystreams#',
    atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
    schema: 'http://schema.org/'
  },
  '@type': 'Object',
  name: 'I love cheese',
  url: 'https://some.url'
};
var successfulResponseData = _objectSpread(_objectSpread({}, errorResponseData), {}, {
  summary: 'Here is your serving of cheese: 🧀',
  'schema:potentialAction': {
    '@id': 'download',
    '@type': 'DownloadAction',
    identifier: 'object-provider',
    name: 'Download'
  },
  'atlassian:downloadUrl': 'https://some-download.url',
  'atlassian:ari': 'ari:cloud:example:1234',
  preview: {
    href: 'https://www.ilovecheese.com'
  },
  icon: {
    '@type': 'Image',
    url: 'https://www.ilovecheese.com/icon.png'
  }
});
var jsonLdResponse = {
  meta: {
    visibility: 'public',
    access: 'granted',
    auth: [],
    definitionId: 'd1',
    key: 'object-provider'
  },
  data: successfulResponseData
};
var entityDataResponse = {
  entityData: {
    id: 'I love cheese',
    displayName: 'I love cheese',
    description: 'Here is your serving of cheese: 🧀',
    url: 'https://some.url',
    lastUpdatedAt: '2025-01-08T22:26:52.501Z',
    thumbnail: {
      externalUrl: 'https://www.ilovecheese.com'
    },
    liveEmbedUrl: 'https://www.ilovecheese.com',
    type: 'FILE',
    inspectUrl: 'https://www.ilovecheese.com',
    iconUrl: 'https://www.ilovecheese.com'
  }
};
var mocks = exports.mocks = {
  success: _objectSpread({}, jsonLdResponse),
  entityDataSuccess: _objectSpread(_objectSpread({}, jsonLdResponse), {}, {
    data: _objectSpread(_objectSpread({}, jsonLdResponse.data), {}, {
      generator: {
        '@type': 'Application',
        icon: {
          '@type': 'Image',
          url: 'https://www.ilovecheese.com'
        },
        name: 'I love cheese'
      }
    }),
    meta: _objectSpread(_objectSpread({}, jsonLdResponse.meta), {}, {
      generator: {
        name: 'I love cheese',
        icon: {
          url: 'https://www.ilovecheese.com'
        }
      }
    })
  }, entityDataResponse),
  notFound: {
    meta: {
      visibility: 'not_found',
      access: 'forbidden',
      auth: [],
      definitionId: 'd1',
      key: 'object-provider'
    },
    data: errorResponseData
  },
  forbidden: {
    meta: {
      visibility: 'restricted',
      access: 'forbidden',
      auth: [{
        key: 'some-flow',
        displayName: 'Flow',
        url: 'https://outbound-auth/flow'
      }],
      definitionId: 'd1',
      key: 'object-provider'
    },
    data: errorResponseData
  },
  forbiddenWithNoAuth: {
    meta: {
      visibility: 'restricted',
      access: 'forbidden',
      auth: [],
      definitionId: 'd1',
      key: 'object-provider'
    },
    data: errorResponseData
  },
  unauthorized: {
    meta: {
      visibility: 'restricted',
      access: 'unauthorized',
      auth: [{
        key: 'some-flow',
        displayName: 'Flow',
        url: 'https://outbound-auth/flow'
      }],
      definitionId: 'd1',
      key: 'object-provider'
    },
    data: errorResponseData
  },
  unauthorizedWithNoAuth: {
    meta: {
      visibility: 'restricted',
      access: 'unauthorized',
      auth: [],
      definitionId: 'd1',
      key: 'object-provider'
    },
    data: errorResponseData
  },
  actionSuccess: {
    meta: {
      visibility: 'public',
      access: 'granted',
      auth: [],
      definitionId: 'd1'
    },
    data: {
      status: 'CompletedStatus'
    }
  },
  analytics: {
    status: 'resolved',
    details: {
      meta: {
        visibility: 'public',
        access: 'granted',
        auth: [],
        definitionId: 'spaghetti-id',
        key: 'spaghetti-key',
        resourceType: 'spaghetti-resource',
        subproduct: 'spaghetti-subproduct',
        product: 'spaghetti-product'
      }
    }
  },
  withDatasource: {
    meta: {
      visibility: 'public',
      access: 'granted',
      auth: [],
      definitionId: 'd1',
      key: 'object-provider'
    },
    data: successfulResponseData,
    datasources: [{
      key: 'datasource-jira-issues',
      parameters: {
        jql: '(text ~ "test*" OR summary ~ "test*") order by created DESC',
        cloudId: '16f8b71e'
      },
      id: '1234-test-id-321',
      ari: 'ari:cloud:linking-platform::datasource/1234-test-id-321',
      description: 'For extracting a list of Jira issues using JQL',
      name: 'Jira issues'
    }]
  }
};
var fakeResponse = exports.fakeResponse = function fakeResponse() {
  return Promise.resolve(mocks.success);
};
var fakeFactory = exports.fakeFactory = function fakeFactory(implementation, implementationPost, implementationPrefetch, implementationAri) {
  return /*#__PURE__*/function (_CardClient) {
    function CustomClient() {
      (0, _classCallCheck2.default)(this, CustomClient);
      return _callSuper(this, CustomClient, arguments);
    }
    (0, _inherits2.default)(CustomClient, _CardClient);
    return (0, _createClass2.default)(CustomClient, [{
      key: "fetchData",
      value: // @ts-ignore
      function () {
        var _fetchData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(url) {
          return _regenerator.default.wrap(function _callee$(_context) {
            while (1) switch (_context.prev = _context.next) {
              case 0:
                _context.next = 2;
                return implementation(url);
              case 2:
                return _context.abrupt("return", _context.sent);
              case 3:
              case "end":
                return _context.stop();
            }
          }, _callee);
        }));
        function fetchData(_x) {
          return _fetchData.apply(this, arguments);
        }
        return fetchData;
      }() // @ts-ignore
    }, {
      key: "postData",
      value: function () {
        var _postData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
          return _regenerator.default.wrap(function _callee2$(_context2) {
            while (1) switch (_context2.prev = _context2.next) {
              case 0:
                _context2.next = 2;
                return implementationPost();
              case 2:
                return _context2.abrupt("return", _context2.sent);
              case 3:
              case "end":
                return _context2.stop();
            }
          }, _callee2);
        }));
        function postData() {
          return _postData.apply(this, arguments);
        }
        return postData;
      }() // @ts-ignore
    }, {
      key: "prefetchData",
      value: function () {
        var _prefetchData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
          return _regenerator.default.wrap(function _callee3$(_context3) {
            while (1) switch (_context3.prev = _context3.next) {
              case 0:
                _context3.next = 2;
                return implementationPrefetch();
              case 2:
                return _context3.abrupt("return", _context3.sent);
              case 3:
              case "end":
                return _context3.stop();
            }
          }, _callee3);
        }));
        function prefetchData() {
          return _prefetchData.apply(this, arguments);
        }
        return prefetchData;
      }() // @ts-ignore
    }, {
      key: "fetchDataAris",
      value: function () {
        var _fetchDataAris = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(aris) {
          return _regenerator.default.wrap(function _callee4$(_context4) {
            while (1) switch (_context4.prev = _context4.next) {
              case 0:
                _context4.next = 2;
                return implementationAri(aris);
              case 2:
                return _context4.abrupt("return", _context4.sent);
              case 3:
              case "end":
                return _context4.stop();
            }
          }, _callee4);
        }));
        function fetchDataAris(_x2) {
          return _fetchDataAris.apply(this, arguments);
        }
        return fetchDataAris;
      }()
    }]);
  }(_linkProvider.CardClient);
};
var waitFor = exports.waitFor = function waitFor() {
  var time = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
  return new Promise(function (res) {
    return setTimeout(res, time);
  });
};