<?php

namespace AC_SYNC\Includes\Classes\Sql\Version {
    if (!defined('ABSPATH'))
        exit; // Exit if accessed directly

    class Action_Wear_Sql_Version_1_0_5 extends Action_Wear_Sql_Version_Abstract implements Action_Wear_Sql_Version_Interface
    {

        public static function versioningScript()
        {
            global $wpdb;
            $charset = $wpdb->get_charset_collate();
            $table = $wpdb->prefix . 'actionwear_orders';

            $sql = "CREATE TABLE IF NOT EXISTS $table (
                id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                wc_order_id BIGINT UNSIGNED NOT NULL,
                sync_status ENUM('pending', 'synced', 'failed') DEFAULT 'pending',
                last_sync_attempt DATETIME NULL,
                sync_response TEXT NULL,
                error_message TEXT NULL,
                created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
                updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                UNIQUE KEY idx_wc_order_id (wc_order_id),
                INDEX idx_sync_status (sync_status)
            ) $charset;";

            require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
            dbDelta($sql);
        }
    }
}
