'use strict';
var formats = require('ajv/lib/compile/formats')();
var equal = require('ajv/lib/compile/equal');
var validate = (function() {
  var refVal = [];
  var refVal1 = {
    "type": "string"
  };
  refVal[1] = refVal1;
  var refVal2 = {
    "description": "The represenation of a path within an OADA server",
    "type": "string",
    "format": "uri-reference"
  };
  refVal[2] = refVal2;
  var refVal3 = {
    "description": "The request methods (a la HTTP) supported by OADA",
    "enum": ["head", "get", "put", "post", "delete"]
  };
  refVal[3] = refVal3;
  return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
    'use strict'; /*# sourceURL=https://formats.openag.io/oada/websockets/request.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.requestId === 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_2 = errors;
          if (typeof data.requestId !== "string") {
            validate.errors = [{
              keyword: 'type',
              dataPath: (dataPath || '') + '.requestId',
              schemaPath: '#/definitions/id/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) {
          var data1 = data.path;
          if (data1 === undefined) {
            valid1 = false;
            validate.errors = [{
              keyword: 'required',
              dataPath: (dataPath || '') + "",
              schemaPath: '#/required',
              params: {
                missingProperty: 'path'
              },
              message: 'should have required property \'path\''
            }];
            return false;
          } else {
            var errs_1 = errors;
            var errs_2 = errors;
            if ((typeof data1 === "number")) {
              if (true) {}
            }
            if (errors === errs_2) {
              if (typeof data1 === "string") {
                if (!formats['uri-reference'].test(data1)) {
                  validate.errors = [{
                    keyword: 'format',
                    dataPath: (dataPath || '') + '.path',
                    schemaPath: '../../oada.schema.json#/definitions/path/format',
                    params: {
                      format: 'uri-reference'
                    },
                    message: 'should match format "uri-reference"'
                  }];
                  return false;
                } else {}
              } else {
                validate.errors = [{
                  keyword: 'type',
                  dataPath: (dataPath || '') + '.path',
                  schemaPath: '../../oada.schema.json#/definitions/path/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.method;
            if (data1 === undefined) {
              valid1 = false;
              validate.errors = [{
                keyword: 'required',
                dataPath: (dataPath || '') + "",
                schemaPath: '#/required',
                params: {
                  missingProperty: 'method'
                },
                message: 'should have required property \'method\''
              }];
              return false;
            } else {
              var errs_1 = errors;
              var errs__1 = errors;
              var valid1 = false;
              var errs_2 = errors;
              var errs_3 = errors;
              var schema3 = refVal3.enum;
              var valid3;
              valid3 = false;
              for (var i3 = 0; i3 < schema3.length; i3++)
                if (equal(data1, schema3[i3])) {
                  valid3 = true;
                  break;
                } if (!valid3) {
                var err = {
                  keyword: 'enum',
                  dataPath: (dataPath || '') + '.method',
                  schemaPath: '../../oada.schema.json#/definitions/method/enum',
                  params: {
                    allowedValues: schema3
                  },
                  message: 'should be equal to one of the allowed values'
                };
                if (vErrors === null) vErrors = [err];
                else vErrors.push(err);
                errors++;
              } else {}
              if (errors === errs_3) {}
              var valid3 = errors === errs_3;
              if (valid3) {}
              if (errors === errs_2) {}
              var valid2 = errors === errs_2;
              valid1 = valid1 || valid2;
              if (!valid1) {
                var errs_2 = errors;
                var schema2 = validate.schema.properties.method.anyOf[1].enum;
                var valid2;
                valid2 = false;
                for (var i2 = 0; i2 < schema2.length; i2++)
                  if (equal(data1, schema2[i2])) {
                    valid2 = true;
                    break;
                  } if (!valid2) {
                  var err = {
                    keyword: 'enum',
                    dataPath: (dataPath || '') + '.method',
                    schemaPath: '#/properties/method/anyOf/1/enum',
                    params: {
                      allowedValues: schema2
                    },
                    message: 'should be equal to one of the allowed values'
                  };
                  if (vErrors === null) vErrors = [err];
                  else vErrors.push(err);
                  errors++;
                } else {}
                if (errors === errs_2) {}
                var valid2 = errors === errs_2;
                valid1 = valid1 || valid2;
                if (!valid1) {}
              }
              if (!valid1) {
                var err = {
                  keyword: 'anyOf',
                  dataPath: (dataPath || '') + '.method',
                  schemaPath: '#/properties/method/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.headers;
              if (data1 === undefined) {
                valid1 = false;
                validate.errors = [{
                  keyword: 'required',
                  dataPath: (dataPath || '') + "",
                  schemaPath: '#/required',
                  params: {
                    missingProperty: 'headers'
                  },
                  message: 'should have required property \'headers\''
                }];
                return false;
              } else {
                var errs_1 = errors;
                if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) {
                  if (true) {
                    var errs__1 = errors;
                    var valid2 = true;
                    if (data1.authorization === undefined) {
                      valid2 = false;
                      validate.errors = [{
                        keyword: 'required',
                        dataPath: (dataPath || '') + '.headers',
                        schemaPath: '#/properties/headers/required',
                        params: {
                          missingProperty: 'authorization'
                        },
                        message: 'should have required property \'authorization\''
                      }];
                      return false;
                    } else {
                      var errs_2 = errors;
                      if (typeof data1.authorization !== "string") {
                        validate.errors = [{
                          keyword: 'type',
                          dataPath: (dataPath || '') + '.headers.authorization',
                          schemaPath: '#/properties/headers/properties/authorization/type',
                          params: {
                            type: 'string'
                          },
                          message: 'should be string'
                        }];
                        return false;
                      }
                      var valid2 = errors === errs_2;
                    }
                    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) {
                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/request.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "This is the format of an OADA websocket request (client to server)",
  "definitions": {
    "id": {
      "type": "string"
    }
  },
  "type": "object",
  "required": ["requestId", "path", "method", "headers"],
  "properties": {
    "requestId": {
      "$ref": "#/definitions/id"
    },
    "path": {
      "$ref": "../../oada.schema.json#/definitions/path"
    },
    "method": {
      "anyOf": [{
        "$ref": "../../oada.schema.json#/definitions/method"
      }, {
        "enum": ["watch", "unwatch", "ping"]
      }]
    },
    "headers": {
      "type": "object",
      "required": ["authorization"],
      "properties": {
        "authorization": {
          "type": "string"
        }
      }
    },
    "data": {
      "description": "The optional data payload of the request"
    }
  }
};
validate.errors = null;
module.exports = validate;