"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.diffToSpec = exports.diffSpecs = exports.standardDiffToggles = exports.allDiffToggles = void 0;

var _cloneDeep = _interopRequireDefault(require("lodash/cloneDeep"));

var _sdkCodegen = require("@looker/sdk-codegen");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var allDiffToggles = ['missing', 'status', 'params', 'type', 'body', 'response'];
exports.allDiffToggles = allDiffToggles;
var standardDiffToggles = ['missing', 'params', 'type', 'body', 'response'];
exports.standardDiffToggles = standardDiffToggles;

var diffSpecs = (lhs, rhs, options) => {
  var includeOptions = (delta, lMethod, rMethod) => options.includes('missing') && (!lMethod || !rMethod) || options.includes('status') && delta.lStatus !== delta.rStatus || options.includes('params') && !!delta.paramsDiff || options.includes('type') && !!delta.typeDiff || options.includes('body') && !!delta.bodyDiff || options.includes('response') && !!delta.responseDiff;

  return (0, _sdkCodegen.compareSpecs)(lhs, rhs, includeOptions);
};

exports.diffSpecs = diffSpecs;

var addMethodToTags = (tags, method) => {
  for (var tag of method.schema.tags) {
    var list = tags[tag];

    if (!list) {
      list = {};
      tags[tag] = list;
    }

    list[method.name] = method;
  }

  return tags;
};

var diffToSpec = (delta, lSpec, rSpec) => {
  var result = (0, _cloneDeep.default)(lSpec);
  result.tags = {};
  result.methods = {};
  delta.forEach(row => {
    var name = row.name;
    var method = lSpec.methods[name];
    if (!method) method = rSpec.methods[name];
    result.methods[name] = method;
    addMethodToTags(result.tags, method);
  });
  result.types = {};
  return result;
};

exports.diffToSpec = diffToSpec;
//# sourceMappingURL=diffUtils.js.map