<?php
/**
* @package CembraPay Payment Gateway for WooCommerce
* @author  Adrian Emil Tudorache
* @license GPL-2.0+
* @link    https://www.tudorache.me/
*/

namespace CembraPayWoo;

if ( ! defined( 'ABSPATH' ) ) {
	header( 'Status: 403 Forbidden' );
	header( 'HTTP/1.1 403 Forbidden' );
	exit;
}

class Legacy {

	function __construct() {
        add_action( 'init', array( $this, 'legacy_data' ) );
        add_action( 'init', array( $this, 'disable_byjuno' ) );
    }

    function legacy_data() {
        
        $byjuno_opts = get_option( 'woocommerce_byjuno_settings' );
        if( $byjuno_opts ) {
            update_option( 'woocommerce_cembrapay_legacy_settings', array(
                'use_order_id_prefix' => $byjuno_opts['use_order_id_prefix'],
                'order_id_prefix'     => $byjuno_opts['order_id_prefix'],
            ) );
        }

    }

    function disable_byjuno() {

        $active_plugins = get_option( 'active_plugins' );

        $plugin_path = 'woocommerce-byjuno/woocommerce-byjuno.php';

        if ( in_array( $plugin_path, $active_plugins ) ) {

            $active_plugins = get_option( 'active_plugins' );
            $byjuno_key = array_search( 'woocommerce-byjuno/woocommerce-byjuno.php', $active_plugins);
            
            if( $byjuno_key ) {
                unset( $active_plugins[$byjuno_key] );
                update_option( 'active_plugins', $active_plugins );
            }

        }

    }

}
?>