<?php

/**
 * Helper class file for audit logging.
 *
 * 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 clearFusionCMS
 * @copyright Copyright (c) 2016 clearFusionCMS. All rights reserved.
 * @link http://clearfusioncms.com
 */

/**
 * cfApiKeyAudit Class
 *
 * Static class to provide API key audit trail logging.
 *
 * @package clearFusionCMS
 */
abstract class cfApiKeyAudit extends cfAudit {

	/**#@+
	 * Action codes.
	 */
	const NEWKEY = 2200;
	const UPDATEKEY = 2210;
	const DELKEY = 2220;
	/**#@-*/

	/**
	 * Record a new key event.
	 *
	 * @param string $name The name of the key.
	 * @param array $roles The roles assigned to the key.
	 */
	static function created($name, $roles) {
		self::record(self::NEWKEY, 'cfApiKey', 0, [
			'name' => $name,
			'roles' => $roles
		]);
	}

	/**
	 * Record a key update event.
	 *
	 * @param string $name The name of the key.
	 * @param array $roles The roles assigned to the key.
	 * @param array $prev The previous data.
	 */
	static function update($name, $roles, $prev) {
		self::record(self::UPDATEKEY, 'cfApiKey', 0, [
			'name' => $name,
			'roles' => $roles
		], $prev);
	}

	/**
	 * Record a key delete event.
	 *
	 * @param string $name The name of the key.
	 * @param array $prev The previous data.
	 */
	static function delete($name, $prev) {
		self::record(self::DELKEY, 'cfApiKey', 0, [
			'name' => $name
		], $prev);
	}
}
