<?php
/**
 * Lifecycle Manager class.
 *
 * This file contains the Lifecycle_Manager class that handles plugin lifecycle hooks registration.
 *
 * @package    Postomatic
 * @subpackage Core
 * @since      1.0.0
 */

namespace Postomatic\Core;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class responsible for registering all plugin lifecycle hooks.
 */
class Lifecycle_Manager {

	/**
	 * Register all lifecycle hooks.
	 *
	 * @return void
	 */
	public static function register_hooks() {
		// Registration of activation hook.
		register_activation_hook(
			POSTOMATIC_PLUGIN_BASENAME,
			array( Activator::class, 'activate' )
		);

		add_action(
			'admin_init',
			function () {
				// Check if our transient is set in the active method.
				if ( get_transient( 'postomatic_do_activation_redirect' ) ) {
					// Delete the transient.
					delete_transient( 'postomatic_do_activation_redirect' );
					// Redirect to your plugin's main page.
					wp_safe_redirect( admin_url( 'admin.php?page=' . POSTOMATIC_PLUGIN_NAME ) );
					exit;
				}
			}
		);

		// Registration of deactivation hook.
		register_deactivation_hook(
			POSTOMATIC_PLUGIN_BASENAME,
			array( Deactivator::class, 'deactivate' )
		);

		// Registration of uninstall hook.
		register_uninstall_hook(
			POSTOMATIC_PLUGIN_BASENAME,
			array( Uninstall::class, 'cleanup' )
		);
	}
}
