'use strict';
var formats = require('ajv/lib/compile/formats')();
var validate = (function() {
  var pattern0 = new RegExp('^resources/.*$');
  var refVal = [];
  var refVal1 = {
    "description": "_id identifies a resource in the OADA API.",
    "type": "string",
    "pattern": "^resources/.*$"
  };
  refVal[1] = refVal1;
  var refVal2 = {
    "description": "_rev is the revision for a resource in the OADA API.",
    "type": "integer"
  };
  refVal[2] = refVal2;
  var refVal3 = (function() {
    var pattern0 = new RegExp('^resources/.*$');
    var refVal = [];
    var refVal1 = {
      "description": "_rev is the revision for a resource in the OADA API.",
      "type": "integer"
    };
    refVal[1] = refVal1;
    var refVal2 = {
      "description": "_id identifies a resource in the OADA API.",
      "type": "string",
      "pattern": "^resources/.*$"
    };
    refVal[2] = refVal2;
    var refVal3 = {
      "description": "_type identifies the content-type of a resource in the OADA API and             is required for all OADA-defined formats.  It usually looks like            application/vnd.oada.something.1+json.",
      "type": "string"
    };
    refVal[3] = refVal3;
    return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
      'use strict';
      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;
          for (var key0 in data) {
            var isAdditional0 = !(false || key0 == '_rev' || key0 == '_id' || key0 == '_type');
            if (isAdditional0) {
              valid1 = false;
              validate.errors = [{
                keyword: 'additionalProperties',
                dataPath: (dataPath || '') + "",
                schemaPath: '#/additionalProperties',
                params: {
                  additionalProperty: '' + key0 + ''
                },
                message: 'should NOT have additional properties'
              }];
              return false;
              break;
            }
          }
          if (valid1) {
            var data1 = data._rev;
            if (data1 === undefined) {
              valid1 = false;
              validate.errors = [{
                keyword: 'required',
                dataPath: (dataPath || '') + "",
                schemaPath: '#/required',
                params: {
                  missingProperty: '_rev'
                },
                message: 'should have required property \'_rev\''
              }];
              return false;
            } else {
              var errs_1 = errors;
              var errs_2 = errors;
              if ((typeof data1 !== "number" || (data1 % 1) || data1 !== data1)) {
                validate.errors = [{
                  keyword: 'type',
                  dataPath: (dataPath || '') + '._rev',
                  schemaPath: '#/definitions/_rev/type',
                  params: {
                    type: 'integer'
                  },
                  message: 'should be integer'
                }];
                return false;
              }
              var valid2 = errors === errs_2;
              if (valid2) {}
              if (errors === errs_1) {}
              var valid1 = errors === errs_1;
            }
            if (valid1) {
              var data1 = data._id;
              if (data1 === undefined) {
                valid1 = true;
              } else {
                var errs_1 = errors;
                var errs_2 = errors;
                if (typeof data1 === "string") {
                  if (!pattern0.test(data1)) {
                    validate.errors = [{
                      keyword: 'pattern',
                      dataPath: (dataPath || '') + '._id',
                      schemaPath: '#/definitions/_id/pattern',
                      params: {
                        pattern: '^resources/.*$'
                      },
                      message: 'should match pattern "^resources/.*$"'
                    }];
                    return false;
                  } else {}
                } else {
                  validate.errors = [{
                    keyword: 'type',
                    dataPath: (dataPath || '') + '._id',
                    schemaPath: '#/definitions/_id/type',
                    params: {
                      type: 'string'
                    },
                    message: 'should be string'
                  }];
                  return false;
                }
                if (errors === errs_2) {}
                var valid2 = errors === errs_2;
                if (valid2) {}
                if (errors === errs_1) {}
                var valid1 = errors === errs_1;
              }
              if (valid1) {
                if (data._type === undefined) {
                  valid1 = true;
                } else {
                  var errs_1 = errors;
                  var errs_2 = errors;
                  if (typeof data._type !== "string") {
                    validate.errors = [{
                      keyword: 'type',
                      dataPath: (dataPath || '') + '._type',
                      schemaPath: '#/definitions/_type/type',
                      params: {
                        type: 'string'
                      },
                      message: 'should be string'
                    }];
                    return false;
                  }
                  var valid2 = errors === errs_2;
                  if (valid2) {}
                  if (errors === errs_1) {}
                  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;
    };
  })();
  refVal3.schema = {
    "$anchor": "versioned",
    "type": "object",
    "required": ["_rev"],
    "properties": {
      "_rev": {
        "$ref": "#/definitions/_rev"
      },
      "_id": {
        "$ref": "#/definitions/_id"
      },
      "_type": {
        "$ref": "#/definitions/_type"
      }
    },
    "additionalProperties": false
  };
  refVal3.errors = null;
  refVal[3] = refVal3;
  var refVal4 = {
    "description": "_type identifies the content-type of a resource in the OADA API and             is required for all OADA-defined formats.  It usually looks like            application/vnd.oada.something.1+json.",
    "type": "string"
  };
  refVal[4] = refVal4;
  return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
    'use strict'; /*# sourceURL=https://formats.openag.io/oada/resource.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;
        var data1 = data._id;
        if (data1 === undefined) {
          valid1 = false;
          validate.errors = [{
            keyword: 'required',
            dataPath: (dataPath || '') + "",
            schemaPath: '#/required',
            params: {
              missingProperty: '_id'
            },
            message: 'should have required property \'_id\''
          }];
          return false;
        } else {
          var errs_1 = errors;
          var errs_2 = errors;
          if (typeof data1 === "string") {
            if (!pattern0.test(data1)) {
              validate.errors = [{
                keyword: 'pattern',
                dataPath: (dataPath || '') + '._id',
                schemaPath: '../oada.schema.json#/definitions/_id/pattern',
                params: {
                  pattern: '^resources/.*$'
                },
                message: 'should match pattern "^resources/.*$"'
              }];
              return false;
            } else {}
          } else {
            validate.errors = [{
              keyword: 'type',
              dataPath: (dataPath || '') + '._id',
              schemaPath: '../oada.schema.json#/definitions/_id/type',
              params: {
                type: 'string'
              },
              message: 'should be string'
            }];
            return false;
          }
          if (errors === errs_2) {}
          var valid2 = errors === errs_2;
          if (valid2) {}
          if (errors === errs_1) {}
          var valid1 = errors === errs_1;
        }
        if (valid1) {
          var data1 = data._rev;
          if (data1 === undefined) {
            valid1 = false;
            validate.errors = [{
              keyword: 'required',
              dataPath: (dataPath || '') + "",
              schemaPath: '#/required',
              params: {
                missingProperty: '_rev'
              },
              message: 'should have required property \'_rev\''
            }];
            return false;
          } else {
            var errs_1 = errors;
            var errs_2 = errors;
            if ((typeof data1 !== "number" || (data1 % 1) || data1 !== data1)) {
              validate.errors = [{
                keyword: 'type',
                dataPath: (dataPath || '') + '._rev',
                schemaPath: '../oada.schema.json#/definitions/_rev/type',
                params: {
                  type: 'integer'
                },
                message: 'should be integer'
              }];
              return false;
            }
            var valid2 = errors === errs_2;
            if (valid2) {}
            if (errors === errs_1) {}
            var valid1 = errors === errs_1;
          }
          if (valid1) {
            if (data._meta === undefined) {
              valid1 = false;
              validate.errors = [{
                keyword: 'required',
                dataPath: (dataPath || '') + "",
                schemaPath: '#/required',
                params: {
                  missingProperty: '_meta'
                },
                message: 'should have required property \'_meta\''
              }];
              return false;
            } else {
              var errs_1 = errors;
              if (!refVal3(data._meta, (dataPath || '') + '._meta', data, '_meta', rootData)) {
                if (vErrors === null) vErrors = refVal3.errors;
                else vErrors = vErrors.concat(refVal3.errors);
                errors = vErrors.length;
              } else {}
              if (errors === errs_1) {}
              var valid1 = errors === errs_1;
            }
            if (valid1) {
              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;
                if (typeof data._type !== "string") {
                  validate.errors = [{
                    keyword: 'type',
                    dataPath: (dataPath || '') + '._type',
                    schemaPath: '../oada.schema.json#/definitions/_type/type',
                    params: {
                      type: 'string'
                    },
                    message: 'should be string'
                  }];
                  return false;
                }
                var valid2 = errors === errs_2;
                if (valid2) {}
                if (errors === errs_1) {}
                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/resource.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": ["_id", "_rev", "_meta", "_type"],
  "properties": {
    "_id": {
      "$ref": "../oada.schema.json#/definitions/_id"
    },
    "_rev": {
      "$ref": "../oada.schema.json#/definitions/_rev"
    },
    "_meta": {
      "$ref": "../oada.schema.json#/definitions/link/definitions/versioned"
    },
    "_type": {
      "$ref": "../oada.schema.json#/definitions/_type"
    }
  }
};
validate.errors = null;
module.exports = validate;