/******************************************************************************
 * Icinga 2                                                                   *
 * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
 *                                                                            *
 * This program is free software; you can redistribute it and/or              *
 * modify it under the terms of the GNU General Public License                *
 * as published by the Free Software Foundation; either version 2             *
 * of the License, or (at your option) any later version.                     *
 *                                                                            *
 * This program is distributed in the hope that it will be useful,            *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
 * GNU General Public License for more details.                               *
 *                                                                            *
 * You should have received a copy of the GNU General Public License          *
 * along with this program; if not, write to the Free Software Foundation     *
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
 ******************************************************************************/

System.assert(Internal.run_with_activation_context(function() {
	var _Internal = Internal.clone()

	template CheckCommand "icinga-check-command" use (_Internal) {
		execute = _Internal.IcingaCheck

		vars.icinga_min_version = ""
	}

	template CheckCommand "cluster-check-command" use (_Internal) {
		execute = _Internal.ClusterCheck
	}

	template CheckCommand "cluster-zone-check-command" use (_Internal) {
		execute = _Internal.ClusterZoneCheck
	}

	template CheckCommand "plugin-check-command" use (_Internal) default {
		execute = _Internal.PluginCheck
	}

	template CheckCommand "clr-check-command" use (_Internal) {
		if (_Internal.ClrCheck) {
			execute = _Internal.ClrCheck
		} else {
			execute = _Internal.NullCheck
		}
	}

	template NotificationCommand "plugin-notification-command" use (_Internal) default {
		execute = _Internal.PluginNotification
	}

	template EventCommand "plugin-event-command" use (_Internal) default {
		execute = _Internal.PluginEvent
	}

	template CheckCommand "dummy-check-command" use (_Internal) {
		execute = _Internal.DummyCheck
	}

	template CheckCommand "random-check-command" use (_Internal) {
		execute = _Internal.RandomCheck
	}

	template CheckCommand "exception-check-command" use (_Internal) {
		execute = _Internal.ExceptionCheck
	}

	template CheckCommand "null-check-command" use (_Internal) {
		execute = _Internal.NullCheck
	}

	template EventCommand "null-event-command" use (_Internal) {
		execute = _Internal.NullEvent
	}

	template TimePeriod "empty-timeperiod" use (_Internal) {
		update = _Internal.EmptyTimePeriod
	}

	template TimePeriod "even-minutes-timeperiod" use (_Internal) {
		update = _Internal.EvenMinutesTimePeriod
	}
}))

var methods = [
	"IcingaCheck",
	"ClusterCheck",
	"ClusterZoneCheck",
	"PluginCheck",
	"ClrCheck",
	"PluginNotification",
	"PluginEvent",
	"DummyCheck",
	"RandomCheck",
	"ExceptionCheck",
	"NullCheck",
	"NullEvent",
	"EmptyTimePeriod",
	"EvenMinutesTimePeriod"
]

for (method in methods) {
	Internal.remove(method)
}