<?php
/**
 * Plugin Name: Jon's Product Feed for Google Merchant Center
 * Plugin URI:  https://plugins.justridingalong.com/google-merchant-feed-plugin-for-woocommerce/
 * Description: Syncs WooCommerce products to Google Merchant Center via the Merchant API. Supports full and delta sync, attribute/term mappings, per-product and per-category exclusions, and availability date from lead_time / due_date meta.
 * Version:     1.4.1
 * Author:      Jon Webb
 * Requires at least: 6.0
 * Requires PHP: 8.1
 * WC requires at least: 7.0
 * WC tested up to: 9.9
 * Tested up to:    6.9
 * License:     GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 */

defined('ABSPATH') || exit;

define('JRA_MERCHANT_VERSION', '1.4.1');
define('JRA_MERCHANT_FILE',    __FILE__);
define('JRA_MERCHANT_DIR',     plugin_dir_path(__FILE__));
define('JRA_MERCHANT_URL',     plugin_dir_url(__FILE__));

// -------------------------------------------------------------------------
// Composer autoloader (google/apiclient etc.)
// -------------------------------------------------------------------------
$autoloader = JRA_MERCHANT_DIR . 'vendor/autoload.php';
if (!file_exists($autoloader)) {
    add_action('admin_notices', function () {
        echo '<div class="notice notice-error"><p><strong>JRA Merchant Feed:</strong> Required libraries are missing. Please reinstall the plugin from a complete zip file.</p></div>';
    });
    return;
}
require_once $autoloader;

// -------------------------------------------------------------------------
// Freemius SDK
// -------------------------------------------------------------------------
require_once JRA_MERCHANT_DIR . 'includes/freemius.php';

// -------------------------------------------------------------------------
// Plugin classes
// -------------------------------------------------------------------------
require_once JRA_MERCHANT_DIR . 'includes/class-encryption.php';
require_once JRA_MERCHANT_DIR . 'includes/class-auth.php';
require_once JRA_MERCHANT_DIR . 'includes/class-logger.php';
require_once JRA_MERCHANT_DIR . 'includes/class-offer-id-map.php';
require_once JRA_MERCHANT_DIR . 'includes/class-product-query.php';
require_once JRA_MERCHANT_DIR . 'includes/class-product-mapper.php';
require_once JRA_MERCHANT_DIR . 'includes/class-sync-service.php';
require_once JRA_MERCHANT_DIR . 'includes/class-report-service.php';
require_once JRA_MERCHANT_DIR . 'includes/class-plugin.php';
require_once JRA_MERCHANT_DIR . 'admin/class-admin.php';

// -------------------------------------------------------------------------
// Boot
// -------------------------------------------------------------------------
add_action('plugins_loaded', function () {
    if (!class_exists('WooCommerce')) {
        add_action('admin_notices', function () {
            echo '<div class="notice notice-error"><p><strong>JRA Merchant Feed</strong> requires WooCommerce to be active.</p></div>';
        });
        return;
    }
    JRA_Merchant_Plugin::maybeUpgrade();
    JRA_Merchant_Plugin::instance();
});

// -------------------------------------------------------------------------
// Activation / deactivation hooks
// -------------------------------------------------------------------------
register_activation_hook(__FILE__, ['JRA_Merchant_Plugin', 'activate']);
register_deactivation_hook(__FILE__, ['JRA_Merchant_Plugin', 'deactivate']);
