"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.actionSchema = exports.actionParamsSchema = exports.actionDomainSchema = exports.actionAlertsFilterSchema = void 0;
var _configSchema = require("@kbn/config-schema");
var _notify_when_schema = require("./notify_when_schema");
var _constants = require("../constants");
/*
 * 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; you may not use this file except in compliance with the Elastic License
 * 2.0.
 */

const actionParamsSchema = _configSchema.schema.recordOf(_configSchema.schema.string(), _configSchema.schema.maybe(_configSchema.schema.any()));
exports.actionParamsSchema = actionParamsSchema;
const actionAlertsFilterQueryFiltersSchema = _configSchema.schema.arrayOf(_configSchema.schema.object({
  query: _configSchema.schema.maybe(_configSchema.schema.recordOf(_configSchema.schema.string(), _configSchema.schema.any())),
  meta: _configSchema.schema.recordOf(_configSchema.schema.string(), _configSchema.schema.any()),
  $state: _configSchema.schema.maybe(_configSchema.schema.object({
    store: _configSchema.schema.oneOf([_configSchema.schema.literal(_constants.filterStateStore.APP_STATE), _configSchema.schema.literal(_constants.filterStateStore.GLOBAL_STATE)])
  }))
}));
const actionDomainAlertsFilterQuerySchema = _configSchema.schema.object({
  kql: _configSchema.schema.string(),
  filters: actionAlertsFilterQueryFiltersSchema,
  dsl: _configSchema.schema.maybe(_configSchema.schema.string())
});
const actionAlertsFilterTimeFrameSchema = _configSchema.schema.object({
  days: _configSchema.schema.arrayOf(_configSchema.schema.oneOf([_configSchema.schema.literal(1), _configSchema.schema.literal(2), _configSchema.schema.literal(3), _configSchema.schema.literal(4), _configSchema.schema.literal(5), _configSchema.schema.literal(6), _configSchema.schema.literal(7)])),
  hours: _configSchema.schema.object({
    start: _configSchema.schema.string(),
    end: _configSchema.schema.string()
  }),
  timezone: _configSchema.schema.string()
});
const actionDomainAlertsFilterSchema = _configSchema.schema.object({
  query: _configSchema.schema.maybe(actionDomainAlertsFilterQuerySchema),
  timeframe: _configSchema.schema.maybe(actionAlertsFilterTimeFrameSchema)
});
const actionFrequencySchema = _configSchema.schema.object({
  summary: _configSchema.schema.boolean(),
  notifyWhen: _notify_when_schema.notifyWhenSchema,
  throttle: _configSchema.schema.nullable(_configSchema.schema.string())
});

/**
 * Unsanitized (domain) action schema, used by internal rules clients
 */
const actionDomainSchema = _configSchema.schema.object({
  uuid: _configSchema.schema.maybe(_configSchema.schema.string()),
  group: _configSchema.schema.string(),
  id: _configSchema.schema.string(),
  actionTypeId: _configSchema.schema.string(),
  params: actionParamsSchema,
  frequency: _configSchema.schema.maybe(actionFrequencySchema),
  alertsFilter: _configSchema.schema.maybe(actionDomainAlertsFilterSchema)
});

/**
 * Sanitized (non-domain) action schema, returned by rules clients for other solutions
 */
exports.actionDomainSchema = actionDomainSchema;
const actionAlertsFilterQuerySchema = _configSchema.schema.object({
  kql: _configSchema.schema.string(),
  filters: actionAlertsFilterQueryFiltersSchema,
  dsl: _configSchema.schema.maybe(_configSchema.schema.string())
});
const actionAlertsFilterSchema = _configSchema.schema.object({
  query: _configSchema.schema.maybe(actionAlertsFilterQuerySchema),
  timeframe: _configSchema.schema.maybe(actionAlertsFilterTimeFrameSchema)
});
exports.actionAlertsFilterSchema = actionAlertsFilterSchema;
const actionSchema = _configSchema.schema.object({
  uuid: _configSchema.schema.maybe(_configSchema.schema.string()),
  group: _configSchema.schema.string(),
  id: _configSchema.schema.string(),
  actionTypeId: _configSchema.schema.string(),
  params: actionParamsSchema,
  frequency: _configSchema.schema.maybe(actionFrequencySchema),
  alertsFilter: _configSchema.schema.maybe(actionAlertsFilterSchema)
});
exports.actionSchema = actionSchema;