'use strict';
var formats = require('ajv/lib/compile/formats')();
var validate = (function() {
  var pattern0 = new RegExp('^resources/.*$');
  var refVal = [];
  var refVal1 = {
    "type": "string"
  };
  refVal[1] = refVal1;
  var refVal2 = {
    "description": "_id identifies a resource in the OADA API.",
    "type": "string",
    "pattern": "^resources/.*$"
  };
  refVal[2] = refVal2;
  return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
    'use strict'; /*# sourceURL=https://formats.openag.io/oada/websockets/response.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.requestId;
        if (data1 === undefined) {
          valid1 = false;
          validate.errors = [{
            keyword: 'required',
            dataPath: (dataPath || '') + "",
            schemaPath: '#/required',
            params: {
              missingProperty: 'requestId'
            },
            message: 'should have required property \'requestId\''
          }];
          return false;
        } else {
          var errs_1 = errors;
          var errs__1 = errors;
          var valid1 = false;
          var errs_2 = errors;
          if (Array.isArray(data1)) {
            if (data1.length < 1) {
              var err = {
                keyword: 'minItems',
                dataPath: (dataPath || '') + '.requestId',
                schemaPath: '#/properties/requestId/anyOf/0/minItems',
                params: {
                  limit: 1
                },
                message: 'should NOT have fewer than 1 items'
              };
              if (vErrors === null) vErrors = [err];
              else vErrors.push(err);
              errors++;
            } else {
              var errs__2 = errors;
              var valid2;
              for (var i2 = 0; i2 < data1.length; i2++) {
                var errs_3 = errors;
                var errs_4 = errors;
                if (typeof data1[i2] !== "string") {
                  var err = {
                    keyword: 'type',
                    dataPath: (dataPath || '') + '.requestId[' + i2 + ']',
                    schemaPath: '#/definitions/id/type',
                    params: {
                      type: 'string'
                    },
                    message: 'should be string'
                  };
                  if (vErrors === null) vErrors = [err];
                  else vErrors.push(err);
                  errors++;
                }
                var valid4 = errors === errs_4;
                if (valid4) {}
                if (errors === errs_3) {}
                var valid3 = errors === errs_3;
                if (!valid3) break;
              }
              if (errs__2 == errors) {}
            }
          } else {
            var err = {
              keyword: 'type',
              dataPath: (dataPath || '') + '.requestId',
              schemaPath: '#/properties/requestId/anyOf/0/type',
              params: {
                type: 'array'
              },
              message: 'should be array'
            };
            if (vErrors === null) vErrors = [err];
            else vErrors.push(err);
            errors++;
          }
          if (errors === errs_2) {}
          var valid2 = errors === errs_2;
          valid1 = valid1 || valid2;
          if (!valid1) {
            var errs_2 = errors;
            var errs_3 = errors;
            if (typeof data1 !== "string") {
              var err = {
                keyword: 'type',
                dataPath: (dataPath || '') + '.requestId',
                schemaPath: '#/definitions/id/type',
                params: {
                  type: 'string'
                },
                message: 'should be string'
              };
              if (vErrors === null) vErrors = [err];
              else vErrors.push(err);
              errors++;
            }
            var valid3 = errors === errs_3;
            if (valid3) {}
            if (errors === errs_2) {}
            var valid2 = errors === errs_2;
            valid1 = valid1 || valid2;
            if (!valid1) {}
          }
          if (!valid1) {
            var err = {
              keyword: 'anyOf',
              dataPath: (dataPath || '') + '.requestId',
              schemaPath: '#/properties/requestId/anyOf',
              params: {},
              message: 'should match some schema in anyOf'
            };
            if (vErrors === null) vErrors = [err];
            else vErrors.push(err);
            errors++;
            validate.errors = vErrors;
            return false;
          } else {
            errors = errs__1;
            if (vErrors !== null) {
              if (errs__1) vErrors.length = errs__1;
              else vErrors = null;
            }
          }
          if (errors === errs_1) {}
          var valid1 = errors === errs_1;
        }
        if (valid1) {
          var data1 = data.status;
          if (data1 === undefined) {
            valid1 = false;
            validate.errors = [{
              keyword: 'required',
              dataPath: (dataPath || '') + "",
              schemaPath: '#/required',
              params: {
                missingProperty: 'status'
              },
              message: 'should have required property \'status\''
            }];
            return false;
          } else {
            var errs_1 = errors;
            if ((typeof data1 !== "number" || (data1 % 1) || data1 !== data1)) {
              validate.errors = [{
                keyword: 'type',
                dataPath: (dataPath || '') + '.status',
                schemaPath: '#/properties/status/type',
                params: {
                  type: 'integer'
                },
                message: 'should be integer'
              }];
              return false;
            }
            var valid1 = errors === errs_1;
          }
          if (valid1) {
            if (data.statusText === undefined) {
              valid1 = true;
            } else {
              var errs_1 = errors;
              if (typeof data.statusText !== "string") {
                validate.errors = [{
                  keyword: 'type',
                  dataPath: (dataPath || '') + '.statusText',
                  schemaPath: '#/properties/statusText/type',
                  params: {
                    type: 'string'
                  },
                  message: 'should be string'
                }];
                return false;
              }
              var valid1 = errors === errs_1;
            }
            if (valid1) {
              var data1 = data.headers;
              if (data1 === undefined) {
                valid1 = true;
              } else {
                var errs_1 = errors;
                if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) {
                  var errs__1 = errors;
                  var valid2 = true;
                  for (var key1 in data1) {
                    var errs_2 = errors;
                    if (typeof data1[key1] !== "string") {
                      validate.errors = [{
                        keyword: 'type',
                        dataPath: (dataPath || '') + '.headers[\'' + key1 + '\']',
                        schemaPath: '#/properties/headers/additionalProperties/type',
                        params: {
                          type: 'string'
                        },
                        message: 'should be string'
                      }];
                      return false;
                    }
                    var valid2 = errors === errs_2;
                    if (!valid2) break;
                  }
                  if (valid2) {}
                  if (errs__1 == errors) {}
                } else {
                  validate.errors = [{
                    keyword: 'type',
                    dataPath: (dataPath || '') + '.headers',
                    schemaPath: '#/properties/headers/type',
                    params: {
                      type: 'object'
                    },
                    message: 'should be object'
                  }];
                  return false;
                }
                if (errors === errs_1) {}
                var valid1 = errors === errs_1;
              }
              if (valid1) {
                var data1 = data.resourceId;
                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 || '') + '.resourceId',
                        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 || '') + '.resourceId',
                      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) {
                  if (data.resource === undefined) {
                    valid1 = true;
                  } else {
                    var errs_1 = errors;
                    var valid1 = errors === errs_1;
                  }
                  if (valid1) {
                    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/websockets/response.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "This is the format of an OADA websocket response (server to client)",
  "definitions": {
    "id": {
      "$ref": "request.schema.json#/properties/requestId"
    }
  },
  "type": "object",
  "required": ["requestId", "status"],
  "properties": {
    "requestId": {
      "description": "Array of request IDs to which this response pertains. A single string is supported only for legacy purposes.",
      "anyOf": [{
        "type": "array",
        "minItems": 1,
        "items": {
          "$ref": "#/definitions/id"
        }
      }, {
        "$ref": "#/definitions/id"
      }]
    },
    "status": {
      "type": "integer"
    },
    "statusText": {
      "type": "string"
    },
    "headers": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      }
    },
    "resourceId": {
      "$ref": "../../oada.schema.json#/definitions/_id"
    },
    "resource": {
      "$comment": "Not sure if this is always actually a resource..."
    },
    "data": {
      "description": "The optional data payload of the request"
    }
  }
};
validate.errors = null;
module.exports = validate;