<?php
if (!defined('ABSPATH')) exit;

class DC_WA_Inquiry_By_XD_Activator {

    public static function activate() {
        global $wpdb;
        
        require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
        
        $table_name = $wpdb->prefix . 'dc_inquiry_xd_inquiries';
        $charset_collate = $wpdb->get_charset_collate();
        
        $sql = "CREATE TABLE IF NOT EXISTS $table_name (
            id mediumint(9) NOT NULL AUTO_INCREMENT,
            product_id bigint(20) NOT NULL,
            inquiry_count int(11) NOT NULL DEFAULT 0,
            last_inquiry_date datetime DEFAULT NULL,
            PRIMARY KEY (id),
            UNIQUE KEY (product_id)
        ) $charset_collate;";
        
        dbDelta($sql);
        
        // Add default options if they don't exist
        if (false === get_option('dc_wa_inquiry_by_xd_button_position')) {
            add_option('dc_wa_inquiry_by_xd_button_position', 'after_add_to_cart');
        }
        if (false === get_option('dc_wa_inquiry_by_xd_button_text')) {
            add_option('dc_wa_inquiry_by_xd_button_text', __('Inquiry on WhatsApp', 'direct-chat-inquiry-by-xd'));
        }
    }
}