<?php

/**
 * THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 * @package fusionLib
 * @copyright Copyright (c) 2016 clearFusionCMS. All rights reserved.
 * @link http://fusionlib.com
 */

/**
 * cfEventNotify Class
 *
 * Class to construct and issue notification events, these events are normally hooked to pass information
 * to services such as Slack.
 *
 * @package clearFusionCMS
 */
class cfEventNotify extends flEvent {

	/**
	 * Construct the notify event.
	 *
	 * @param int $level The importance level of the notifcation 1 - 5.
	 * @param string $title The title for the notification.
	 * @param string $message The message body for the notification.
	 */
	function __construct($level, $title, $message) {
		parent::__construct('system.notify', array(
			'level' => $level,
			'title' => $title,
			'message' => $message
		));
	}

	/**
	 * Add a mention to the event.
	 *
	 * @param string $mention The list of mentions.
	 * @return cfEventNotify This object.
	 */
	function mention($mention) {
		$this->params['mention'] = $mention;
		return $this;
	}

	/**
	 * Add a link to the event.
	 *
	 * @param string $link The address to link to.
	 * @return cfEventNotify This object.
	 */
	function link($link) {
		$this->params['link'] = $link;
		return $this;
	}

	/**
	 * Add a field to the event.
	 *
	 * @param string $title The title of the filed.
	 * @param string $value The value of the field.
	 * @return cfEventNotify This object.
	 */
	function addField($title, $value) {
		if(!isset($this->params['fields']))
			$this->params['fields'] = array();

		$this->params['fields'][] = array(
			'title' => $title,
			'value' => $value
		);

		return $this;
	}
}