<?php

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

    class Action_Wear_Sql_Version_1_0_9 extends Action_Wear_Sql_Version_Abstract implements Action_Wear_Sql_Version_Interface
    {

        public static function versioningScript()
        {
            global $wpdb;
            $charset_collate = $wpdb->get_charset_collate();
            $table_name = $wpdb->prefix . 'actionwear_sync_state';

            $sql = "CREATE TABLE IF NOT EXISTS $table_name (
                id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
                process_key VARCHAR(64) NOT NULL,
                state_key VARCHAR(64) NOT NULL,
                state_value LONGTEXT,
                created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
                updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
                UNIQUE KEY idx_process_state (process_key, state_key)
            ) $charset_collate;";

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