<?php
/**
 * Plugin activation class.
 *
 * @package SaveToWishlist\Classes
 * @since 1.0.0
 */
namespace SaveToWishlist\Classes;

use SaveToWishlist\Helpers\Helper_Database;

/**
 * Class Activate
 *
 * This class handles the plugin activation.
 */
class Activate {
    /**
     * Activate the plugin.
     *
     * @since 1.0.3 Added review dismiss date.
     */
    public static function activate() {
        // Create wishlist tables.
        Helper_Database::create_tables();

        // Create wishlist page.
        if ( ! get_option( 'stwlite_wishlist_page' ) ) {
            $page = array(
                'post_title'   => 'Wishlist',
                'post_content' => '[saveto_wishlist]',
                'post_status'  => 'publish',
                'post_type'    => 'page',
            );

            $page_id = wp_insert_post( $page );

            update_option( 'stwlite_wishlist_page', $page_id );
        }

        // Set review dismiss date.
        if ( ! get_option( 'stwlite_review_dismiss_date' ) ) {
            update_option( 'stwlite_review_dismiss_date', time() );
        }

        // Flush rewrite rules to ensure that custom post types are registered.
        flush_rewrite_rules();
    }
}
