"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getMaintenanceWindowRoute = void 0;
var _lib = require("../../../lib");
var _types = require("../../../../types");
var _common = require("../../../../../common");
var _get = require("../../../../../common/routes/maintenance_window/apis/get");
var _transforms = require("../../transforms");
/*
 * 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 getMaintenanceWindowRoute = (router, licenseState) => {
  router.get({
    path: `${_types.INTERNAL_ALERTING_API_MAINTENANCE_WINDOW_PATH}/{id}`,
    validate: {
      params: _get.getParamsSchemaV1
    },
    options: {
      tags: [`access:${_common.MAINTENANCE_WINDOW_API_PRIVILEGES.READ_MAINTENANCE_WINDOW}`]
    }
  }, router.handleLegacyErrors((0, _lib.verifyAccessAndContext)(licenseState, async function (context, req, res) {
    licenseState.ensureLicenseForMaintenanceWindow();
    const maintenanceWindowClient = (await context.alerting).getMaintenanceWindowClient();
    const params = req.params;
    const maintenanceWindow = await maintenanceWindowClient.get({
      id: params.id
    });
    const response = {
      body: (0, _transforms.transformMaintenanceWindowToResponseV1)(maintenanceWindow)
    };
    return res.ok(response);
  })));
};
exports.getMaintenanceWindowRoute = getMaintenanceWindowRoute;