<?php

defined( 'ABSPATH' ) || exit;

// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
// -- Justification: T4A_ (Twint4All) is the historical, stable prefix of this
// plugin used across ~60 constants and dozens of files since 1.0.0. Renaming
// to PAY4ALL_TWINT_* would touch every consumer for zero user-facing benefit
// and no realistic collision risk (no other plugin uses T4A_).

// Read the version directly from the plugin header so there's a single
// source of truth (the Version: line of pay4all-for-twint.php). Wrapped in
// an immediately-invoked closure so no file-scope variable leaks into the
// global namespace (Plugin Check flags any top-level $var as "global").
define( 'T4A_PLUGIN_VERSION', ( function () {
    $file   = dirname( dirname( __FILE__ ) ) . '/pay4all-for-twint.php';
    $header = function_exists( 'get_file_data' )
        ? get_file_data( $file, [ 'Version' => 'Version' ] )
        : [ 'Version' => '' ];
    return ! empty( $header[ 'Version' ] ) ? $header[ 'Version' ] : '0.0.0';
} )() );
define( 'T4A_DB_VERSION', '2.1.0' );
define( 'T4A_PLUGIN_NAME', 'Pay4All for TWINT' );
define( 'T4A_PLUGIN_DISPLAY_NAME', 'Pay4All for TWINT' );
define( 'T4A_SOFTWARE_NAME', 'Pay4All for TWINT' );

defined( 'T4A_ENVIRONMENT' ) || define( 'T4A_ENVIRONMENT', 'prod' );

define( 'T4A_DEBUG', false );
define( 'T4A_PREFIX', 't4a_twint' );
define( 'T4A_PLUGIN_DIRNAME', basename( dirname( dirname( __FILE__ ) ) ) );
define( 'T4A_OPENSSL_ACTIVE', extension_loaded( 'openssl' ) );
define( 'T4A_PLUGIN_DOWNLOAD_ID', 751 );

define( 'T4A_PLUGIN_PATH', dirname( dirname( __FILE__ ) ) );
define( 'T4A_PLUGIN_URL', plugin_dir_url( __DIR__ ) );
define( 'T4A_PLUGIN_FILE', dirname( dirname( __FILE__ ) ) . '/pay4all-for-twint.php' );
define( 'T4A_UPLOAD_DIR', wp_upload_dir()[ 'basedir' ] . '/t4a_twint/' );

//define( 'T4A_MAX_LOG_FILE_SIZE', 2 ); // In MB.
define( 'T4A_MAX_NUM_LOG_FILES', 30 );

// Payment
define( 'T4A_CHECK_PAYMENT_SUCCESS_AFTER', 300 );

// Logs
define( 'T4A_DELETE_LOGS_AFTER', get_option( 't4a_twint_delete_logs_after' ) ?: 30 ); // days

// System check
define( 'T4A_TIMES_RETRY_SYSTEM_CHECK', 3 );
define( 'T4A_SYSTEM_CHECK_RELATIVE_INTERVAL', 2 );

define( 'T4A_DEFAULT_SYSTEM_CHECK_INTERVAL', 24 ); // Hours
define( 'T4A_SYSTEM_CHECK_INTERVAL', ( function () {
    $interval = get_option( 't4a_twint_system_check_interval' );
    if ( ! $interval || $interval < 1 ) {
        $interval = T4A_DEFAULT_SYSTEM_CHECK_INTERVAL;
    }
    return $interval;
} )() );

define( 'T4A_ORDER_CHECK_INTERVAL', get_option( 't4a_twint_order_check_interval' ) ?: 15 );
define( 'T4A_ORDER_CHECK_MIN_TIME', 5 );
define( 'T4A_ORDER_CHECK_MAX_TIME', 120 );
define( 'T4A_ORDER_CHECK_NUM_POSTS', 10 );

define( 'T4A_DEFAULT_ASYNC_REQUEST_IMMEDIATE', 'yes' );
define( 'T4A_DEFAULT_ASYNC_REQUEST_SHUTDOWN', 'no' );
define( 'T4A_DEFAULT_ASYNC_REQUEST_AJAX', 'yes' );
define( 'T4A_DEFAULT_ASYNC_REQUEST_CRON', 'yes' );
define( 'T4A_DEFAULT_SOAP_INTERVAL', 5 );

define( 'T4A_DEFAULT_STATUS_ORDER', 'processing' );
define( 'T4A_DEFAULT_STATUS_VIRTUAL', 'completed' );
define( 'T4A_DEFAULT_STATUS_DEFERRED', 'on-hold' );
define( 'T4A_DEFAULT_CONNECTION_TIMEOUT', 25 );

define( 'T4A_WEBHOOK_TIMEOUT', 60 * 10 ); // 10 min
// 30 minutes : realistic upper bound for a TWINT checkout flow. The
// customer redirects to the TWINT app, may complete a slow QR flow,
// come back to the merchant with the signed URL. Below ~10 min some
// legit returns would be rejected. Wide enough for real-world use,
// tight enough to render captured URLs useless within one workday.
define( 'T4A_REDIRECT_SIGNATURE_EXPIRATION', 1800 );

define( 'T4A_TEMPLATES_PATH', T4A_PLUGIN_PATH . '/templates/' );

define( 'T4A_INTEGRATION', 'direct' );

define('T4A_UPDATE_SUBS_PER_BG_TASK', 10);
