'use strict';
var formats = require('ajv/lib/compile/formats')();
var equal = require('ajv/lib/compile/equal');
var validate = (function() {
  var refVal = [];
  return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
    'use strict'; /*# sourceURL=https://formats.openag.io/trellis/gs1/produce/shipping_event/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.originator === undefined) {
          valid1 = true;
        } else {
          var errs_1 = errors;
          if (typeof data.originator !== "string") {
            validate.errors = [{
              keyword: 'type',
              dataPath: (dataPath || '') + '.originator',
              schemaPath: '#/properties/originator/type',
              params: {
                type: 'string'
              },
              message: 'should be string'
            }];
            return false;
          }
          var valid1 = errors === errs_1;
        }
        if (valid1) {
          if (data.trading_partner === undefined) {
            valid1 = true;
          } else {
            var errs_1 = errors;
            if (typeof data.trading_partner !== "string") {
              validate.errors = [{
                keyword: 'type',
                dataPath: (dataPath || '') + '.trading_partner',
                schemaPath: '#/properties/trading_partner/type',
                params: {
                  type: 'string'
                },
                message: 'should be string'
              }];
              return false;
            }
            var valid1 = errors === errs_1;
          }
          if (valid1) {
            if (data.activity_type === undefined) {
              valid1 = true;
            } else {
              var errs_1 = errors;
              if (typeof data.activity_type !== "string") {
                validate.errors = [{
                  keyword: 'type',
                  dataPath: (dataPath || '') + '.activity_type',
                  schemaPath: '#/properties/activity_type/type',
                  params: {
                    type: 'string'
                  },
                  message: 'should be string'
                }];
                return false;
              }
              var valid1 = errors === errs_1;
            }
            if (valid1) {
              if (data.originator_type === undefined) {
                valid1 = true;
              } else {
                var errs_1 = errors;
                if (typeof data.originator_type !== "string") {
                  validate.errors = [{
                    keyword: 'type',
                    dataPath: (dataPath || '') + '.originator_type',
                    schemaPath: '#/properties/originator_type/type',
                    params: {
                      type: 'string'
                    },
                    message: 'should be string'
                  }];
                  return false;
                }
                var valid1 = errors === errs_1;
              }
              if (valid1) {
                if (data.receiver_type === undefined) {
                  valid1 = true;
                } else {
                  var errs_1 = errors;
                  if (typeof data.receiver_type !== "string") {
                    validate.errors = [{
                      keyword: 'type',
                      dataPath: (dataPath || '') + '.receiver_type',
                      schemaPath: '#/properties/receiver_type/type',
                      params: {
                        type: 'string'
                      },
                      message: 'should be string'
                    }];
                    return false;
                  }
                  var valid1 = errors === errs_1;
                }
                if (valid1) {
                  if (data.timestamp === undefined) {
                    valid1 = true;
                  } else {
                    var errs_1 = errors;
                    if (typeof data.timestamp !== "string") {
                      validate.errors = [{
                        keyword: 'type',
                        dataPath: (dataPath || '') + '.timestamp',
                        schemaPath: '#/properties/timestamp/type',
                        params: {
                          type: 'string'
                        },
                        message: 'should be string'
                      }];
                      return false;
                    }
                    var valid1 = errors === errs_1;
                  }
                  if (valid1) {
                    if (data.activity_no === undefined) {
                      valid1 = true;
                    } else {
                      var errs_1 = errors;
                      if (typeof data.activity_no !== "string") {
                        validate.errors = [{
                          keyword: 'type',
                          dataPath: (dataPath || '') + '.activity_no',
                          schemaPath: '#/properties/activity_no/type',
                          params: {
                            type: 'string'
                          },
                          message: 'should be string'
                        }];
                        return false;
                      }
                      var valid1 = errors === errs_1;
                    }
                    if (valid1) {
                      if (data.contents_of_shipment === undefined) {
                        valid1 = true;
                      } else {
                        var errs_1 = errors;
                        if (Array.isArray(data.contents_of_shipment)) {
                          var errs__1 = errors;
                          var valid1;
                          if (errs__1 == errors) {}
                        } else {
                          validate.errors = [{
                            keyword: 'type',
                            dataPath: (dataPath || '') + '.contents_of_shipment',
                            schemaPath: '#/properties/contents_of_shipment/type',
                            params: {
                              type: 'array'
                            },
                            message: 'should be array'
                          }];
                          return false;
                        }
                        if (errors === errs_1) {}
                        var valid1 = errors === errs_1;
                      }
                      if (valid1) {
                        if (data._id === undefined) {
                          valid1 = true;
                        } else {
                          var errs_1 = errors;
                          if (typeof data._id !== "string") {
                            validate.errors = [{
                              keyword: 'type',
                              dataPath: (dataPath || '') + '._id',
                              schemaPath: '#/properties/_id/type',
                              params: {
                                type: 'string'
                              },
                              message: 'should be string'
                            }];
                            return false;
                          }
                          var valid1 = errors === errs_1;
                        }
                        if (valid1) {
                          var data1 = data._rev;
                          if (data1 === undefined) {
                            valid1 = true;
                          } else {
                            var errs_1 = errors;
                            if ((typeof data1 !== "number" || (data1 % 1) || data1 !== data1)) {
                              validate.errors = [{
                                keyword: 'type',
                                dataPath: (dataPath || '') + '._rev',
                                schemaPath: '#/properties/_rev/type',
                                params: {
                                  type: 'integer'
                                },
                                message: 'should be integer'
                              }];
                              return false;
                            }
                            var valid1 = errors === errs_1;
                          }
                          if (valid1) {
                            var data1 = data._meta;
                            if (data1 === undefined) {
                              valid1 = true;
                            } else {
                              var errs_1 = errors;
                              if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) {
                                if (true) {
                                  var errs__1 = errors;
                                  var valid2 = true;
                                  if (data1._id === undefined) {
                                    valid2 = false;
                                    validate.errors = [{
                                      keyword: 'required',
                                      dataPath: (dataPath || '') + '._meta',
                                      schemaPath: '#/properties/_meta/required',
                                      params: {
                                        missingProperty: '_id'
                                      },
                                      message: 'should have required property \'_id\''
                                    }];
                                    return false;
                                  } else {
                                    var errs_2 = errors;
                                    if (typeof data1._id !== "string") {
                                      validate.errors = [{
                                        keyword: 'type',
                                        dataPath: (dataPath || '') + '._meta._id',
                                        schemaPath: '#/properties/_meta/properties/_id/type',
                                        params: {
                                          type: 'string'
                                        },
                                        message: 'should be string'
                                      }];
                                      return false;
                                    }
                                    var valid2 = errors === errs_2;
                                  }
                                  if (valid2) {
                                    var data2 = data1._rev;
                                    if (data2 === undefined) {
                                      valid2 = false;
                                      validate.errors = [{
                                        keyword: 'required',
                                        dataPath: (dataPath || '') + '._meta',
                                        schemaPath: '#/properties/_meta/required',
                                        params: {
                                          missingProperty: '_rev'
                                        },
                                        message: 'should have required property \'_rev\''
                                      }];
                                      return false;
                                    } else {
                                      var errs_2 = errors;
                                      if ((typeof data2 !== "number" || (data2 % 1) || data2 !== data2)) {
                                        validate.errors = [{
                                          keyword: 'type',
                                          dataPath: (dataPath || '') + '._meta._rev',
                                          schemaPath: '#/properties/_meta/properties/_rev/type',
                                          params: {
                                            type: 'integer'
                                          },
                                          message: 'should be integer'
                                        }];
                                        return false;
                                      }
                                      var valid2 = errors === errs_2;
                                    }
                                    if (valid2) {}
                                  }
                                  if (errs__1 == errors) {}
                                }
                              } else {
                                validate.errors = [{
                                  keyword: 'type',
                                  dataPath: (dataPath || '') + '._meta',
                                  schemaPath: '#/properties/_meta/type',
                                  params: {
                                    type: 'object'
                                  },
                                  message: 'should be object'
                                }];
                                return false;
                              }
                              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 schema1 = validate.schema.properties._type.enum;
                                var valid1;
                                valid1 = false;
                                for (var i1 = 0; i1 < schema1.length; i1++)
                                  if (equal(data._type, schema1[i1])) {
                                    valid1 = true;
                                    break;
                                  } if (!valid1) {
                                  validate.errors = [{
                                    keyword: 'enum',
                                    dataPath: (dataPath || '') + '._type',
                                    schemaPath: '#/properties/_type/enum',
                                    params: {
                                      allowedValues: schema1
                                    },
                                    message: 'should be equal to one of the allowed values'
                                  }];
                                  return false;
                                } else {}
                                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/trellis/gs1/produce/shipping_event/v1.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "GS1 receiving event has certain required fields and and array element",
  "properties": {
    "originator": {
      "description": "gln of the data originator and the data owner",
      "type": "string"
    },
    "trading_partner": {
      "description": "gln of the trading partner",
      "type": "string"
    },
    "activity_type": {
      "description": "defines the business process that taking place",
      "type": "string",
      "examples": ["purchase_order", "production_work_order", "bill_of_landing"]
    },
    "originator_type": {
      "description": "trading_partner_type of the originating trading partner",
      "type": "string",
      "examples": ["grower", "supplier", "manufacturer", "processor", "distributor", "retailor"]
    },
    "receiver_type": {
      "description": "trading_partner_type of the receiving trading partner",
      "type": "string",
      "examples": ["grower", "supplier", "manufacturer", "processor", "distributor", "retailor"]
    },
    "timestamp": {
      "description": "defines the timestamp of the data capture",
      "type": "string"
    },
    "activity_no": {
      "description": "defines a unique identifer to implicate the transaction id of the business event - purchase order id etc",
      "type": "string"
    },
    "contents_of_shipment": {
      "description": "all shipping trading items",
      "type": "array",
      "items": {
        "description": "item is sold/shipped by one trading partner to the other"
      }
    },
    "_id": {
      "description": "_id identifies a resource in the OADA API.",
      "type": "string"
    },
    "_rev": {
      "description": "_rev is the revision string for a resource in the OADA API.",
      "type": "integer"
    },
    "_meta": {
      "description": "_meta is a link to the meta document for a resources.",
      "properties": {
        "_id": {
          "description": "_id identifies a resource in the OADA API.",
          "type": "string"
        },
        "_rev": {
          "description": "_rev is the revision string for a resource in the OADA API.",
          "type": "integer"
        }
      },
      "required": ["_id", "_rev"],
      "type": "object"
    },
    "_type": {
      "enum": ["application/trellis.vnd.gs1.produce.shipping_event.1+json"]
    }
  },
  "additionalProperties": true,
  "required": ["_type"],
  "type": "object",
  "examples": []
};
validate.errors = null;
module.exports = validate;