'use strict';
var formats = require('ajv/lib/compile/formats')();
var equal = require('ajv/lib/compile/equal');
var validate = (function() {
  var refVal = [];
  var refVal1 = {
    "description": "Indicates the type of change that occured.",
    "enum": ["merge", "delete"]
  };
  refVal[1] = refVal1;
  return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
    'use strict'; /*# sourceURL=https://formats.openag.io/oada/change/v1.schema.json */
    var vErrors = null;
    var errors = 0;
    if (rootData === undefined) rootData = data;
    if ((data && typeof data === "object" && !Array.isArray(data))) {
      if (true) {
        var errs__0 = errors;
        var valid1 = true;
        if (data.type === undefined) {
          valid1 = false;
          validate.errors = [{
            keyword: 'required',
            dataPath: (dataPath || '') + "",
            schemaPath: '#/required',
            params: {
              missingProperty: 'type'
            },
            message: 'should have required property \'type\''
          }];
          return false;
        } else {
          var errs_1 = errors;
          var errs_2 = errors;
          var schema2 = refVal1.enum;
          var valid2;
          valid2 = false;
          for (var i2 = 0; i2 < schema2.length; i2++)
            if (equal(data.type, schema2[i2])) {
              valid2 = true;
              break;
            } if (!valid2) {
            validate.errors = [{
              keyword: 'enum',
              dataPath: (dataPath || '') + '.type',
              schemaPath: '#/definitions/type/enum',
              params: {
                allowedValues: schema2
              },
              message: 'should be equal to one of the allowed values'
            }];
            return false;
          } else {}
          if (errors === errs_2) {}
          var valid2 = errors === errs_2;
          if (valid2) {}
          if (errors === errs_1) {}
          var valid1 = errors === errs_1;
        }
        if (valid1) {
          if (data.body === undefined) {
            valid1 = false;
            validate.errors = [{
              keyword: 'required',
              dataPath: (dataPath || '') + "",
              schemaPath: '#/required',
              params: {
                missingProperty: 'body'
              },
              message: 'should have required property \'body\''
            }];
            return false;
          } else {
            var errs_1 = errors;
            var valid1 = errors === errs_1;
          }
          if (valid1) {}
        }
        if (errs__0 == errors) {}
      }
    } else {
      validate.errors = [{
        keyword: 'type',
        dataPath: (dataPath || '') + "",
        schemaPath: '#/type',
        params: {
          type: 'object'
        },
        message: 'should be object'
      }];
      return false;
    }
    if (errors === 0) {}
    validate.errors = vErrors;
    return errors === 0;
  };
})();
validate.schema = {
  "$id": "https://formats.openag.io/oada/change/v1.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "type": {
      "description": "Indicates the type of change that occured.",
      "enum": ["merge", "delete"]
    }
  },
  "type": "object",
  "description": "Tree-based change representation (OADA v1)",
  "required": ["type", "body"],
  "properties": {
    "type": {
      "$ref": "#/definitions/type"
    },
    "body": {
      "$comment": "Should probably narrow this schema down",
      "description": "The contents of what was changed."
    }
  },
  "examples": [{
    "body": {
      "test": "abc",
      "_rev": 1
    },
    "type": "merge"
  }]
};
validate.errors = null;
module.exports = validate;