<?php

/**
 * Plugin Name: Engage Rate Boost
 * Plugin URI:  https://wordpress.com/plugins/engage-rate-boost
 * Description: Plugin that allows users to rate and comment on posts and products.
 * Version:     1.0
 * Author:      BiHV
 * Author URI:  https://github.com/bihv
 * License:     GPL2
 */
// Ensure the file is being run within the WordPress environment
if ( !defined( 'ABSPATH' ) ) {
    exit;
    // Exit if accessed directly
}
if ( !function_exists( 'erbwp_fs' ) ) {
    // Create a helper function for easy SDK access.
    function erbwp_fs() {
        global $erbwp_fs;
        if ( !isset( $erbwp_fs ) ) {
            // Include Freemius SDK.
            require_once dirname( __FILE__ ) . '/vendor/freemius/wordpress-sdk/start.php';
            $erbwp_fs = fs_dynamic_init( array(
                'id'               => '15751',
                'slug'             => 'engage-rate-boost',
                'type'             => 'plugin',
                'public_key'       => 'pk_5e4853983117ee204becbf85689ed',
                'is_premium'       => false,
                'premium_suffix'   => 'Pro',
                'has_addons'       => false,
                'has_paid_plans'   => true,
                'is_org_compliant' => true,
                'trial'            => array(
                    'days'               => 14,
                    'is_require_payment' => true,
                ),
                'menu'             => array(
                    'slug'    => 'erbwp-settings',
                    'support' => false,
                    'parent'  => array(
                        'slug' => 'options-general.php',
                    ),
                ),
                'is_live'          => true,
            ) );
        }
        return $erbwp_fs;
    }

    // Init Freemius.
    erbwp_fs();
    // Signal that SDK was initiated.
    do_action( 'erbwp_fs_loaded' );
}
function erbwp_create_reviews_table() {
    global $wpdb;
    $table_name = $wpdb->prefix . 'reviews';
    $charset_collate = $wpdb->get_charset_collate();
    $sql = "CREATE TABLE {$table_name} (\n        id INT AUTO_INCREMENT PRIMARY KEY,\n        post_id INT NOT NULL,\n        user_id INT NULL,\n        name VARCHAR(255) NOT NULL,\n        email VARCHAR(255) NOT NULL,\n        comment TEXT NOT NULL,\n        rating INT NOT NULL,\n        criteria JSON NULL,\n        date DATETIME DEFAULT CURRENT_TIMESTAMP,\n        is_hidden BOOLEAN DEFAULT FALSE,\n        hidden_reason TEXT NULL,\n        parent_id INT NULL,\n        is_migrated_from_wp BOOLEAN DEFAULT FALSE\n    ) {$charset_collate};";
    require_once ABSPATH . 'wp-admin/includes/upgrade.php';
    dbDelta( $sql );
}

register_activation_hook( __FILE__, 'erbwp_create_reviews_table' );
require_once plugin_dir_path( __FILE__ ) . 'erbwp-functions.php';
add_action(
    'erbwp_send_scheduled_email_action',
    'erbwp_send_scheduled_email',
    10,
    1
);
require_once plugin_dir_path( __FILE__ ) . 'erbwp-settings.php';
require_once plugin_dir_path( __FILE__ ) . 'erbwp-user.php';
require_once plugin_dir_path( __FILE__ ) . 'erbwp-admin.php';