'use strict';

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }

var React = require('react');
var PropTypes = require('prop-types');
var _ = require('lodash');

// const debug = require('debug')('mongodb-compass:validation:exists');

var RuleCategoryExists = function (_React$Component) {
  _inherits(RuleCategoryExists, _React$Component);

  function RuleCategoryExists() {
    _classCallCheck(this, RuleCategoryExists);

    return _possibleConstructorReturn(this, (RuleCategoryExists.__proto__ || Object.getPrototypeOf(RuleCategoryExists)).apply(this, arguments));
  }

  _createClass(RuleCategoryExists, [{
    key: 'render',


    /**
     * Render ValidationHeader.
     *
     * @returns {React.Component} The view component.
     */
    value: function render() {
      // nothing to render for the "Exists" rule.
      return null;
    }
  }], [{
    key: 'getInitialParameters',


    /**
     * get the initial parameters for this rule category.
     *
     * @return {Object}   the parameters for this rule.
     */
    value: function getInitialParameters() {
      return {};
    }

    /**
     * Convert the parameters describing the state of this rule to a query
     * value that MongoDB understands.
     *
     * @return {Object}   the value describing this rule.
     */

  }, {
    key: 'paramsToQuery',
    value: function paramsToQuery() {
      return {
        $exists: true
      };
    }

    /**
     * Convert the a query value returned from the server to an object of
     * parameters describing the state of this rule.
     *
     * @param {Object} query   The query value for this field.
     *
     * @return {Object|Boolean}  the parameters describing the state of this rule
     *                           or false if the query cannot be described by
     *                           this rule.
     */

  }, {
    key: 'queryToParams',
    value: function queryToParams(query) {
      if (_.isEqual(query, { $exists: true })) {
        return {};
      }
      return false;
    }
  }]);

  return RuleCategoryExists;
}(React.Component);

RuleCategoryExists.propTypes = {
  id: PropTypes.string.isRequired,
  parameters: PropTypes.object.isRequired
};

RuleCategoryExists.displayName = 'RuleCategoryExists';

module.exports = RuleCategoryExists;