<?php
/**
 * Plugin Name: Fusion WooDoo
 * Plugin URI: https://fusionsoft.ca
 * Description: Seamless Odoo integration for WooCommerce — sync products, orders, invoices, and inventory.
 * Version: 1.0.0
 * Author: Fusion Central
 * Author URI: https://fusionsoft.ca
 * Requires at least: 6.0
 * Requires PHP: 8.0
 * WC requires at least: 8.0
 * WC tested up to: 9.0
 * Text Domain: fusion-woodoo
 * Domain Path: /languages
 * License: GPL v2 or later
 */

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

define('FUSION_WOODOO_VERSION', '1.0.0');
define('FUSION_WOODOO_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('FUSION_WOODOO_PLUGIN_URL', plugin_dir_url(__FILE__));

add_action('plugins_loaded', function() {
    if (!class_exists('WooCommerce')) {
        add_action('admin_notices', function() {
            echo '<div class="error"><p><strong>Fusion WooDoo</strong> requires WooCommerce to be installed and active.</p></div>';
        });
        return;
    }
    require_once FUSION_WOODOO_PLUGIN_DIR . 'includes/class-fusion-woodoo.php';
    Fusion_WooDoo::instance();
});

register_activation_hook(__FILE__, function() {
    $dirs = ['invoices', 'deliveries'];
    foreach ($dirs as $dir) {
        $path = wp_upload_dir()['basedir'] . '/fusion-woodoo/' . $dir;
        wp_mkdir_p($path);
        file_put_contents($path . '/.htaccess', 'deny from all');
    }
    flush_rewrite_rules();
});

register_deactivation_hook(__FILE__, function() {
    if (file_exists(FUSION_WOODOO_PLUGIN_DIR . 'includes/class-webhooks.php')) {
        require_once FUSION_WOODOO_PLUGIN_DIR . 'includes/class-webhooks.php';
        Fusion_WooDoo_Webhooks::unregister_all();
    }
    flush_rewrite_rules();
});
