"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.updateOptionsSchema = exports.searchOptionsSchemas = exports.schemaAndOr = exports.savedObjectSchema = exports.referencesSchema = exports.referenceSchema = exports.objectTypeToGetResultSchema = exports.createResultSchema = exports.createOptionsSchemas = exports.apiError = void 0;
var _configSchema = require("@kbn/config-schema");
/*
 * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
 * or more contributor license agreements. Licensed under the Elastic License
 * 2.0 and the Server Side Public License, v 1; you may not use this file except
 * in compliance with, at your election, the Elastic License 2.0 or the Server
 * Side Public License, v 1.
 */

const apiError = _configSchema.schema.object({
  error: _configSchema.schema.string(),
  message: _configSchema.schema.string(),
  statusCode: _configSchema.schema.number(),
  metadata: _configSchema.schema.object({}, {
    unknowns: 'allow'
  })
});
exports.apiError = apiError;
const referenceSchema = _configSchema.schema.object({
  name: _configSchema.schema.maybe(_configSchema.schema.string()),
  type: _configSchema.schema.string(),
  id: _configSchema.schema.string()
}, {
  unknowns: 'forbid'
});
exports.referenceSchema = referenceSchema;
const referencesSchema = _configSchema.schema.arrayOf(referenceSchema);
exports.referencesSchema = referencesSchema;
const savedObjectSchema = attributesSchema => _configSchema.schema.object({
  id: _configSchema.schema.string(),
  type: _configSchema.schema.string(),
  version: _configSchema.schema.maybe(_configSchema.schema.string()),
  createdAt: _configSchema.schema.maybe(_configSchema.schema.string()),
  updatedAt: _configSchema.schema.maybe(_configSchema.schema.string()),
  error: _configSchema.schema.maybe(apiError),
  attributes: attributesSchema,
  references: referencesSchema,
  namespaces: _configSchema.schema.maybe(_configSchema.schema.arrayOf(_configSchema.schema.string())),
  originId: _configSchema.schema.maybe(_configSchema.schema.string())
}, {
  unknowns: 'allow'
});
exports.savedObjectSchema = savedObjectSchema;
const objectTypeToGetResultSchema = soSchema => _configSchema.schema.object({
  item: soSchema,
  meta: _configSchema.schema.object({
    outcome: _configSchema.schema.oneOf([_configSchema.schema.literal('exactMatch'), _configSchema.schema.literal('aliasMatch'), _configSchema.schema.literal('conflict')]),
    aliasTargetId: _configSchema.schema.maybe(_configSchema.schema.string()),
    aliasPurpose: _configSchema.schema.maybe(_configSchema.schema.oneOf([_configSchema.schema.literal('savedObjectConversion'), _configSchema.schema.literal('savedObjectImport')]))
  }, {
    unknowns: 'forbid'
  })
}, {
  unknowns: 'forbid'
});

// its recommended to create a subset of this schema for stricter validation
exports.objectTypeToGetResultSchema = objectTypeToGetResultSchema;
const createOptionsSchemas = {
  id: _configSchema.schema.maybe(_configSchema.schema.string()),
  references: _configSchema.schema.maybe(referencesSchema),
  overwrite: _configSchema.schema.maybe(_configSchema.schema.boolean()),
  version: _configSchema.schema.maybe(_configSchema.schema.string()),
  refresh: _configSchema.schema.maybe(_configSchema.schema.boolean()),
  initialNamespaces: _configSchema.schema.maybe(_configSchema.schema.arrayOf(_configSchema.schema.string()))
};
exports.createOptionsSchemas = createOptionsSchemas;
const schemaAndOr = _configSchema.schema.oneOf([_configSchema.schema.literal('AND'), _configSchema.schema.literal('OR')]);

// its recommended to create a subset of this schema for stricter validation
exports.schemaAndOr = schemaAndOr;
const searchOptionsSchemas = {
  page: _configSchema.schema.maybe(_configSchema.schema.number()),
  perPage: _configSchema.schema.maybe(_configSchema.schema.number()),
  sortField: _configSchema.schema.maybe(_configSchema.schema.string()),
  sortOrder: _configSchema.schema.maybe(_configSchema.schema.oneOf([_configSchema.schema.literal('asc'), _configSchema.schema.literal('desc')])),
  fields: _configSchema.schema.maybe(_configSchema.schema.arrayOf(_configSchema.schema.string())),
  search: _configSchema.schema.maybe(_configSchema.schema.string()),
  searchFields: _configSchema.schema.maybe(_configSchema.schema.oneOf([_configSchema.schema.string(), _configSchema.schema.arrayOf(_configSchema.schema.string())])),
  rootSearchFields: _configSchema.schema.maybe(_configSchema.schema.arrayOf(_configSchema.schema.string())),
  hasReference: _configSchema.schema.maybe(_configSchema.schema.oneOf([referenceSchema, _configSchema.schema.arrayOf(referenceSchema)])),
  hasReferenceOperator: _configSchema.schema.maybe(schemaAndOr),
  hasNoReference: _configSchema.schema.maybe(_configSchema.schema.oneOf([referenceSchema, _configSchema.schema.arrayOf(referenceSchema)])),
  hasNoReferenceOperator: _configSchema.schema.maybe(schemaAndOr),
  defaultSearchOperator: _configSchema.schema.maybe(schemaAndOr),
  namespaces: _configSchema.schema.maybe(_configSchema.schema.arrayOf(_configSchema.schema.string())),
  type: _configSchema.schema.maybe(_configSchema.schema.string()),
  filter: _configSchema.schema.maybe(_configSchema.schema.string()),
  pit: _configSchema.schema.maybe(_configSchema.schema.object({
    id: _configSchema.schema.string(),
    keepAlive: _configSchema.schema.maybe(_configSchema.schema.string())
  }))
};

// its recommended to create a subset of this schema for stricter validation
exports.searchOptionsSchemas = searchOptionsSchemas;
const updateOptionsSchema = {
  references: _configSchema.schema.maybe(referencesSchema),
  version: _configSchema.schema.maybe(_configSchema.schema.string()),
  refresh: _configSchema.schema.maybe(_configSchema.schema.oneOf([_configSchema.schema.boolean(), _configSchema.schema.literal('wait_for')])),
  upsert: attributesSchema => _configSchema.schema.maybe(savedObjectSchema(attributesSchema)),
  retryOnConflict: _configSchema.schema.maybe(_configSchema.schema.number())
};
exports.updateOptionsSchema = updateOptionsSchema;
const createResultSchema = soSchema => _configSchema.schema.object({
  item: soSchema
}, {
  unknowns: 'forbid'
});
exports.createResultSchema = createResultSchema;