<?php
/**
 * Upgrade — version-bump migrations.
 *
 * @package WPNest_Returns_For_WooCommerce
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class WPNest_RFW_Upgrade {

    /**
     * Migration dispatcher — call from main plugin's init() before module bootstrapping.
     * Compares stored version to current version and runs migrations as needed.
     */
    public static function maybe_run() {
        $current = (string) get_option( 'wpnest_rfw_version', '0.0.0' );
        if ( WPNEST_RFW_VERSION === $current ) {
            return;
        }
        // 1.0.0: the activator used to store the English string "Return this order"
        // as the default button label, which prevented the translated label from
        // showing on localised installs. Clear it so class-frontend.php::button_label()
        // falls back to __() and WP's just-in-time loader translates it.
        $label = get_option( 'wpnest_rfw_button_label', '' );
        if ( 'Return this order' === $label ) {
            update_option( 'wpnest_rfw_button_label', '' );
        }

        update_option( 'wpnest_rfw_version', WPNEST_RFW_VERSION );
    }
}
