'use strict';
var formats = require('ajv/lib/compile/formats')();
var equal = require('ajv/lib/compile/equal');
var validate = (function() {
  var refVal = [];
  var refVal1 = (function() {
    var refVal = [];
    var refVal1 = {
      "$id": "https://formats.openag.io/oada/service/job/update.schema.json",
      "$schema": "http://json-schema.org/draft-07/schema#",
      "description": "A list of updates as job progresses. Keys shall be sorted in time order.",
      "type": "object",
      "properties": {
        "status": {
          "description": "Status of job at the time of update",
          "type": "string"
        },
        "time": {
          "description": "ISO8601 UTC date-time of update time",
          "type": "string"
        },
        "meta": {
          "description": "Additional meta data about the status update"
        }
      },
      "required": ["status", "time"],
      "examples": [{
        "status": "started",
        "time": "2018-11-14T20:20:39+00:00",
        "meta": {
          "example": "data"
        }
      }]
    };
    refVal[1] = refVal1;
    return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
      'use strict'; /*# sourceURL=https://formats.openag.io/oada/service/job.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.service === undefined) {
            valid1 = false;
            validate.errors = [{
              keyword: 'required',
              dataPath: (dataPath || '') + "",
              schemaPath: '#/required',
              params: {
                missingProperty: 'service'
              },
              message: 'should have required property \'service\''
            }];
            return false;
          } else {
            var errs_1 = errors;
            if (typeof data.service !== "string") {
              validate.errors = [{
                keyword: 'type',
                dataPath: (dataPath || '') + '.service',
                schemaPath: '#/properties/service/type',
                params: {
                  type: 'string'
                },
                message: 'should be string'
              }];
              return false;
            }
            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;
              if (typeof data.type !== "string") {
                validate.errors = [{
                  keyword: 'type',
                  dataPath: (dataPath || '') + '.type',
                  schemaPath: '#/properties/type/type',
                  params: {
                    type: 'string'
                  },
                  message: 'should be string'
                }];
                return false;
              }
              var valid1 = errors === errs_1;
            }
            if (valid1) {
              var data1 = data.config;
              if (data1 === undefined) {
                valid1 = true;
              } else {
                var errs_1 = errors;
                if ((!data1 || typeof data1 !== "object" || Array.isArray(data1))) {
                  validate.errors = [{
                    keyword: 'type',
                    dataPath: (dataPath || '') + '.config',
                    schemaPath: '#/properties/config/type',
                    params: {
                      type: 'object'
                    },
                    message: 'should be object'
                  }];
                  return false;
                }
                var valid1 = errors === errs_1;
              }
              if (valid1) {
                var data1 = data.result;
                if (data1 === undefined) {
                  valid1 = true;
                } else {
                  var errs_1 = errors;
                  if ((!data1 || typeof data1 !== "object" || Array.isArray(data1))) {
                    validate.errors = [{
                      keyword: 'type',
                      dataPath: (dataPath || '') + '.result',
                      schemaPath: '#/properties/result/type',
                      params: {
                        type: 'object'
                      },
                      message: 'should be object'
                    }];
                    return false;
                  }
                  var valid1 = errors === errs_1;
                }
                if (valid1) {
                  if (data.status === undefined) {
                    valid1 = true;
                  } else {
                    var errs_1 = errors;
                    if (typeof data.status !== "string") {
                      validate.errors = [{
                        keyword: 'type',
                        dataPath: (dataPath || '') + '.status',
                        schemaPath: '#/properties/status/type',
                        params: {
                          type: 'string'
                        },
                        message: 'should be string'
                      }];
                      return false;
                    }
                    var valid1 = errors === errs_1;
                  }
                  if (valid1) {
                    var data1 = data.updates;
                    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 data2 = data1[key1];
                          var errs_2 = errors;
                          var errs_3 = errors;
                          if ((data2 && typeof data2 === "object" && !Array.isArray(data2))) {
                            if (true) {
                              var errs__3 = errors;
                              var valid4 = true;
                              if (data2.status === undefined) {
                                valid4 = false;
                                validate.errors = [{
                                  keyword: 'required',
                                  dataPath: (dataPath || '') + '.updates[\'' + key1 + '\']',
                                  schemaPath: './job/update.schema.json/required',
                                  params: {
                                    missingProperty: 'status'
                                  },
                                  message: 'should have required property \'status\''
                                }];
                                return false;
                              } else {
                                var errs_4 = errors;
                                if (typeof data2.status !== "string") {
                                  validate.errors = [{
                                    keyword: 'type',
                                    dataPath: (dataPath || '') + '.updates[\'' + key1 + '\'].status',
                                    schemaPath: './job/update.schema.json/properties/status/type',
                                    params: {
                                      type: 'string'
                                    },
                                    message: 'should be string'
                                  }];
                                  return false;
                                }
                                var valid4 = errors === errs_4;
                              }
                              if (valid4) {
                                if (data2.time === undefined) {
                                  valid4 = false;
                                  validate.errors = [{
                                    keyword: 'required',
                                    dataPath: (dataPath || '') + '.updates[\'' + key1 + '\']',
                                    schemaPath: './job/update.schema.json/required',
                                    params: {
                                      missingProperty: 'time'
                                    },
                                    message: 'should have required property \'time\''
                                  }];
                                  return false;
                                } else {
                                  var errs_4 = errors;
                                  if (typeof data2.time !== "string") {
                                    validate.errors = [{
                                      keyword: 'type',
                                      dataPath: (dataPath || '') + '.updates[\'' + key1 + '\'].time',
                                      schemaPath: './job/update.schema.json/properties/time/type',
                                      params: {
                                        type: 'string'
                                      },
                                      message: 'should be string'
                                    }];
                                    return false;
                                  }
                                  var valid4 = errors === errs_4;
                                }
                                if (valid4) {
                                  if (valid4) {}
                                }
                              }
                              if (errs__3 == errors) {}
                            }
                          } else {
                            validate.errors = [{
                              keyword: 'type',
                              dataPath: (dataPath || '') + '.updates[\'' + key1 + '\']',
                              schemaPath: './job/update.schema.json/type',
                              params: {
                                type: 'object'
                              },
                              message: 'should be object'
                            }];
                            return false;
                          }
                          if (errors === errs_3) {}
                          var valid3 = errors === errs_3;
                          if (valid3) {}
                          if (errors === errs_2) {}
                          var valid2 = errors === errs_2;
                          if (!valid2) break;
                        }
                        if (valid2) {}
                        if (errs__1 == errors) {}
                      } else {
                        validate.errors = [{
                          keyword: 'type',
                          dataPath: (dataPath || '') + '.updates',
                          schemaPath: '#/properties/updates/type',
                          params: {
                            type: 'object'
                          },
                          message: 'should be object'
                        }];
                        return false;
                      }
                      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;
    };
  })();
  refVal1.schema = {
    "$id": "https://formats.openag.io/oada/service/job.schema.json",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "description": "The format for an @oada/jobs job queue job.",
    "type": "object",
    "properties": {
      "service": {
        "description": "Service name which job is for",
        "type": "string"
      },
      "type": {
        "description": "Service specific identifier of job type",
        "type": "string"
      },
      "config": {
        "description": "Job spceific configuration object",
        "type": "object"
      },
      "result": {
        "description": "Final result of job",
        "type": "object"
      },
      "status": {
        "description": "Current status of job",
        "type": "string"
      },
      "updates": {
        "description": "A list of updates as job progresses. Keys shall be sorted in time order.",
        "type": "object",
        "additionalProperties": {
          "$ref": "./job/update.schema.json"
        }
      }
    },
    "required": ["service", "type"],
    "examples": [{
      "service": "shares",
      "type": "trading-partner",
      "config": {
        "resource": {
          "_id": "resources/TESTCOI1"
        },
        "trading-partner": {
          "_id": "resources/1b0yRTKhv21Rkbkt32PSokJOOrs_TP_LEGACYFARM"
        },
        "path": "/bookmarks/trellisfw/trading-partners/1b0yRTKhv21Rkbkt32PSokJOOrs_TP_LEGACYFARM/bookmarks/trellisfw/cois"
      },
      "status": "pending",
      "updates": {
        "1bF4ELuQwqU3CjDOsn2NF0d7Deu": {
          "status": "started",
          "time": "2018-11-14T20:20:39+00:00"
        },
        "1bF4GjXWJvj6FJEXCiAj8DatQTD": {
          "status": "pending",
          "time": "2018-11-13T20:20:39+00:00",
          "information": "Share requires manual approval"
        }
      }
    }, {
      "service": "shares",
      "type": "trading-partner",
      "config": {
        "resource": {
          "_id": "resources/TESTCOI1"
        },
        "trading-partner": {
          "_id": "resources/1b0yRTKhv21Rkbkt32PSokJOOrs_TP_LEGACYFARM"
        },
        "path": "/bookmarks/trellisfw/trading-partners/1b0yRTKhv21Rkbkt32PSokJOOrs_TP_LEGACYFARM/bookmarks/trellisfw/cois"
      },
      "status": "success",
      "results": {
        "path": "/bookmarks/new/path"
      },
      "updates": {
        "1bWH1wv07R4XEhwyK2T3wJ2kLMo": {
          "status": "success",
          "time": "2018-11-15T20:20:39+00:00",
          "information": {
            "approved": "john"
          }
        },
        "1bF4ELuQwqU3CjDOsn2NF0d7Deu": {
          "status": "started",
          "time": "2018-11-14T20:20:39+00:00"
        },
        "1bF4GjXWJvj6FJEXCiAj8DatQTD": {
          "status": "pending",
          "time": "2018-11-13T20:20:39+00:00",
          "information": "Share requires manual approval"
        }
      }
    }]
  };
  refVal1.errors = null;
  refVal[1] = refVal1;
  return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
    'use strict'; /*# sourceURL=https://formats.openag.io/trellis/service/ift-pusher/sync.schema.json */
    var vErrors = null;
    var errors = 0;
    if (rootData === undefined) rootData = data;
    if ((data && typeof data === "object" && !Array.isArray(data))) {
      var errs__0 = errors;
      var valid1 = true;
      if (data.service === undefined) {
        valid1 = true;
      } else {
        var errs_1 = errors;
        var schema1 = validate.schema.properties.service.const;
        var valid1 = equal(data.service, schema1);
        if (!valid1) {
          validate.errors = [{
            keyword: 'const',
            dataPath: (dataPath || '') + '.service',
            schemaPath: '#/properties/service/const',
            params: {
              allowedValue: schema1
            },
            message: 'should be equal to constant'
          }];
          return false;
        } else {}
        if (errors === errs_1) {}
        var valid1 = errors === errs_1;
      }
      if (valid1) {
        if (data.type === undefined) {
          valid1 = true;
        } else {
          var errs_1 = errors;
          var schema1 = validate.schema.properties.type.const;
          var valid1 = equal(data.type, schema1);
          if (!valid1) {
            validate.errors = [{
              keyword: 'const',
              dataPath: (dataPath || '') + '.type',
              schemaPath: '#/properties/type/const',
              params: {
                allowedValue: schema1
              },
              message: 'should be equal to constant'
            }];
            return false;
          } else {}
          if (errors === errs_1) {}
          var valid1 = errors === errs_1;
        }
        if (valid1) {
          var data1 = data.config;
          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.resourceId === undefined) {
                  valid2 = false;
                  validate.errors = [{
                    keyword: 'required',
                    dataPath: (dataPath || '') + '.config',
                    schemaPath: '#/properties/config/required',
                    params: {
                      missingProperty: 'resourceId'
                    },
                    message: 'should have required property \'resourceId\''
                  }];
                  return false;
                } else {
                  var errs_2 = errors;
                  if (typeof data1.resourceId !== "string") {
                    validate.errors = [{
                      keyword: 'type',
                      dataPath: (dataPath || '') + '.config.resourceId',
                      schemaPath: '#/properties/config/properties/resourceId/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 || '') + '.config',
                schemaPath: '#/properties/config/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) {
      var errs_1 = errors;
      if (!refVal1(data, (dataPath || ''), parentData, parentDataProperty, rootData)) {
        if (vErrors === null) vErrors = refVal1.errors;
        else vErrors = vErrors.concat(refVal1.errors);
        errors = vErrors.length;
      } else {}
      if (errors === errs_1) {}
      var valid1 = errors === errs_1;
      if (valid1) {}
      if (errors === 0) {}
    }
    validate.errors = vErrors;
    return errors === 0;
  };
})();
validate.schema = {
  "$id": "https://formats.openag.io/trellis/service/ift-pusher/sync.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "Extension of @oada/job format for ift-pusher",
  "type": "object",
  "allOf": [{
    "$ref": "../../../oada/service/job.schema.json"
  }],
  "properties": {
    "service": {
      "description": "Service Name",
      "const": "ift-pusher"
    },
    "type": {
      "description": "IFT Synchronization Job",
      "const": "sync"
    },
    "config": {
      "description": "Job specific configuration object",
      "type": "object",
      "required": ["resourceId"],
      "properties": {
        "resourceId": {
          "description": "id for virtualized pdf",
          "type": "string"
        }
      }
    },
    "result": {
      "description": "Final result of job"
    }
  },
  "examples": [{
    "service": "ift-pusher",
    "type": "sync",
    "config": {
      "resourceId": "resources/oivnoseklnvaoeij329814ng"
    },
    "status": "pending",
    "updates": {
      "aoihngklsdmfjoavin2398havj": {
        "status": "started",
        "time": "2019-10-20T20:07:21+00:00",
        "information": "started"
      }
    }
  }]
};
validate.errors = null;
module.exports = validate;