<?php

namespace Booktics\Onboard;

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

use Booktics\Contracts\Hookable_Service_Contract;

/**
 * Handles initialization of onboarding process for first-time plugin installation
 *
 * @package Booktics/Onboard
 */
class Init_Onboard implements Hookable_Service_Contract {

    /**
     * Register admin init action
     *
     * @return void
     */
    public function register() {
        add_action( 'admin_init', array( $this, 'init' ) );
    }

    /**
     * Initializes onboarding process by checking if plugin is installed
     * If not installed, sets installation flag and redirects to onboarding page
     *
     * @return void
     */
    public function init() {
        $is_installed = get_option( 'booktics_is_installed', false );
        if ( ! $is_installed ) {
            update_option( 'booktics_is_installed', true );
            wp_safe_redirect( admin_url( 'admin.php?page=booktics#/onboard' ) );
            exit();
        }
    }
}
