<?php

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Fired during plugin activation
 *
 * @link       https://webequipe.com
 * @since      1.0.0
 *
 * @package    Webequipe_Spin_Win_Wheel
 * @subpackage Webequipe_Spin_Win_Wheel/includes
 */

/**
 * Fired during plugin activation.
 *
 * This class defines all code necessary to run during the plugin's activation.
 *
 * @since      1.0.0
 * @package    Webequipe_Spin_Win_Wheel
 * @subpackage Webequipe_Spin_Win_Wheel/includes
 * @author     Webequipe <support@webequipe.com>
 */
class Webequipe_Spin_Win_Wheel_Activator {

    /**
     * Plugin activation hook
     */
    public static function activate() {
        self::create_tables();
    }

    /**
     * Create necessary database tables
     */
    public static function create_tables() {
        global $wpdb;

        $charset_collate = $wpdb->get_charset_collate();

        $sqls = [];

        $sqls[] = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}spin_emails` (
            `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
            `spin_id` int(11) DEFAULT NULL,
            `spin_item_unique_id` varchar(20) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
            `spin_label` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
            `email` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
            `name` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
            `phone` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
            `page_url` text COLLATE utf8mb4_unicode_520_ci,
            `coupon_code` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
            `coupon_applied` varchar(10) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
            `claim` varchar(10) COLLATE utf8mb4_unicode_520_ci NOT NULL DEFAULT 'no',
            `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
            `updated_at` datetime DEFAULT NULL,
            PRIMARY KEY (`id`)
        ) $charset_collate";



        $sqls[] = "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}spin_posts` (
                `id` int(11) unsigned NOT NULL AUTO_INCREMENT,

                
                `spin_title` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `spin_description` text COLLATE utf8mb4_unicode_520_ci,
                `spin_status` varchar(50) COLLATE utf8mb4_unicode_520_ci DEFAULT 'inactive',

                
                `spin_display_setting` text COLLATE utf8mb4_unicode_520_ci,  
                `spin_type` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `spin_position` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `display_field_setting` text COLLATE utf8mb4_unicode_520_ci,

               
                `auto_minute` int(11) DEFAULT NULL,
                `spin_duration` int(11) DEFAULT NULL,
                `display_after` int(11) DEFAULT NULL,
                `display_after_same_email` int(11) DEFAULT NULL,

                
                `template_setting` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,

               
                `card_background` varchar(20) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `card_color` varchar(20) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `card_boder_radius` int(11) DEFAULT NULL,
                `card_boder_padding` int(11) DEFAULT NULL,

               
                `wheel_center_background` varchar(20) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `wheel_center_boder_color` varchar(20) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `wheel_center_boder_width` int(11) DEFAULT NULL,
                `wheel_center_image_icon` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `custom_wheel_center_image_icon` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,

                
                `wheel_stroke_border_color` varchar(20) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `wheel_stroke_border_size` int(11) DEFAULT NULL,
                `wheel_stroke_font_size` int(11) DEFAULT NULL,
                `wheel_stroke_font_family` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `wheel_stroke_font_style` varchar(50) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,

                
                `from_design_alinment` varchar(50) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `from_button_text` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `from_button_color` varchar(20) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `from_button_background_color` varchar(20) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,

                `initial_button_text` varchar(100) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `initial_button_color` varchar(20) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `initial_button_background_color` varchar(20) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,

                
                `win_message` text COLLATE utf8mb4_unicode_520_ci,
                `loss_message` text COLLATE utf8mb4_unicode_520_ci,

                
                `send_email` varchar(10) COLLATE utf8mb4_unicode_520_ci DEFAULT 'no',
                `from_name` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `from_address` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `from_subject` varchar(255) COLLATE utf8mb4_unicode_520_ci DEFAULT NULL,
                `from_message` text COLLATE utf8mb4_unicode_520_ci,

                
                `admin_geting_email` varchar(10) COLLATE utf8mb4_unicode_520_ci DEFAULT 'no',

                
                `spins` longtext COLLATE utf8mb4_unicode_520_ci,

                
                `created_by` bigint(20) UNSIGNED NOT NULL,
                `created_at` datetime NOT NULL,
                `deleted` tinyint(1) NOT NULL DEFAULT '0',
                `deleted_by` int(11) DEFAULT NULL,
                `deleted_at` datetime DEFAULT NULL,

                PRIMARY KEY (`id`)
            ) $charset_collate";


        if (!function_exists('dbDelta')) {
            require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        }

        foreach ($sqls as $sql) {
            dbDelta($sql);
        }
    }
}
