<?php

namespace WPKIN_SHOP_MANAGER;

use WPKIN_SHOP_MANAGER\Modules\EmployeeManager;

if ( ! defined( 'ABSPATH' ) ) {
	wp_die( esc_html__( 'You can\'t access this page', 'shop-manager' ) );
}

/**
 * Plugin Installation Class
 *
 * @since 1.0.0
 */
class Installation {

	/**
	 * Installation class constructor
	 *
	 * Database
	 *
	 * @since 1.0.0
	 */
	public function __construct() {
		$this->wpkin_activate();
		$this->wpkin_save_settings_default_data();
		EmployeeManager::register_roles();
		EmployeeManager::create_activity_log_table();
	}

	/**
	 * After activate Plugin
	 *
	 * @since 1.0.0
	 */
	public function wpkin_activate() {

		$installed = get_option( 'wpkin_sm_installed' );

		if ( ! $installed ) {
			update_option( 'wpkin_sm_installed', time() );
		}

		update_option( 'wpkin_sm_version', WPKIN_SM_VERSION );

		add_option( 'wpkin_sm_activation_redirect', true );
	}

	private function wpkin_save_settings_default_data() {

		$settings = get_option( 'wpkin_sm_admin_settings' );

		if ( $settings ) {
			return false;
		}

		$settings_data = Helper::wpkin_plugin_default_settings_data();

		update_option( 'wpkin_sm_order_tab_settings', $settings_data['orders'] );
		update_option( 'wpkin_sm_admin_settings', $settings_data );
	}
}
