<?php
/**
 * Audit log event-type constants.
 *
 * Keeping these centralised makes it harder to misspell an event name
 * at a recording site and lets the admin UI / tests enumerate them.
 *
 * @package KaizenCoders\MagicLink\AuditLog
 */

namespace KaizenCoders\MagicLink\AuditLog;

class Events {

	const GENERATED = 'generated';
	const SENT      = 'sent';
	const OPENED    = 'opened';
	const USED      = 'used';
	const EXPIRED   = 'expired';
	const REVOKED   = 'revoked';
	const FAILED    = 'failed';
	const DELIVERED = 'delivered';
	const BOUNCED   = 'bounced';

	/**
	 * Every known event type.
	 *
	 * @return array
	 */
	public static function all() {
		return array(
			self::GENERATED,
			self::SENT,
			self::OPENED,
			self::USED,
			self::EXPIRED,
			self::REVOKED,
			self::FAILED,
			self::DELIVERED,
			self::BOUNCED,
		);
	}

	/**
	 * Human-readable label for an event type.
	 *
	 * @param  string $event Event type.
	 *
	 * @return string
	 */
	public static function label( $event ) {
		$map = array(
			self::GENERATED => __( 'Generated', 'magic-link' ),
			self::SENT      => __( 'Sent', 'magic-link' ),
			self::OPENED    => __( 'Opened', 'magic-link' ),
			self::USED      => __( 'Used', 'magic-link' ),
			self::EXPIRED   => __( 'Expired', 'magic-link' ),
			self::REVOKED   => __( 'Revoked', 'magic-link' ),
			self::FAILED    => __( 'Failed', 'magic-link' ),
			self::DELIVERED => __( 'Delivered', 'magic-link' ),
			self::BOUNCED   => __( 'Bounced', 'magic-link' ),
		);
		return isset( $map[ $event ] ) ? $map[ $event ] : ucwords( str_replace( '_', ' ', $event ) );
	}
}
