<?php

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

class AIEO_DMM_ERP_Bridge extends AIEO_DMM_Module_Base {

    public function get_id() { return 'erp_bridge'; }
    public function get_label() { return __('ERP Bridge', 'ai-eshop-optimizer'); }
    public function get_priority() { return 120; }
    public function get_group() { return 'tools'; }

    public function is_pro_locked() { return true; }
    public function get_pro_promo() {
        return array(
            'title'       => __('ERP Bridge', 'ai-eshop-optimizer'),
            'description' => __('Two-way bridge between WooCommerce and your physical-store ERP. Stock, prices, customers, and orders flow live across both systems — no manual CSV exports, no nightly batch jobs, no out-of-sync inventory.', 'ai-eshop-optimizer'),
            'bullets'     => array(
                __('Live stock sync — sell on Woo, the shelf count drops in the ERP within seconds.', 'ai-eshop-optimizer'),
                __('Configurable hook contract — pick which entities + directions are bridged.', 'ai-eshop-optimizer'),
                __('Works against any MariaDB / MySQL ERP via the encrypted ERP Database connection.', 'ai-eshop-optimizer'),
            ),
        );
    }

    public function render_subtab() {
        $this->render_template('erp-bridge.php', array(
            'hooks' => $this->get_hook_contract(),
        ));
    }

    
    public function get_hook_contract() {
        return array(
            array(
                'type' => 'filter',
                'name' => 'aieo_dmm_export_orders_row',
                'description' => __('Mutate an individual row just before it is written to the orders export CSV. Passed the $row value array (the fixed 31-column SoftOne row, positional) plus a context array: ["result" => the SQL row object whose properties are the column aliases, "order_id" => int]. Mutate values in place — the SoftOne column set is fixed (the ERP import template depends on it), so do not add or remove columns.', 'ai-eshop-optimizer'),
                'example' => "add_filter('aieo_dmm_export_orders_row', function(\$row, \$ctx){\n    // \$ctx['order_id'] = order id; \$ctx['result'] = the SoftOne SQL row object.\n    // \$row is the fixed 31-value SoftOne column array (do not add/remove columns).\n    return \$row;\n}, 10, 2);",
            ),
            array(
                'type' => 'action',
                'name' => 'aieo_dmm_after_import_stock',
                'description' => __('Fired after each product has its stock updated by the Stock Import module. Use for ERP callbacks.', 'ai-eshop-optimizer'),
                'example' => "add_action('aieo_dmm_after_import_stock', function(\$product_id, \$stock, \$job_id){\n    // push a mirror update back to the ERP…\n}, 10, 3);",
            ),
            array(
                'type' => 'filter',
                'name' => 'aieo_dmm_feed_item',
                'description' => __('Mutate a single feed item just before it is serialised. Receives $row, $feed_slug, $feed_config.', 'ai-eshop-optimizer'),
                'example' => "add_filter('aieo_dmm_feed_item', function(\$row, \$slug, \$feed){\n    if (\$slug === 'skroutz') { \$row['g:custom_label_0'] = 'vip'; }\n    return \$row;\n}, 10, 3);",
            ),
            array(
                'type' => 'filter',
                'name' => 'aieo_dmm_needs_taxonomy',
                'description' => __('Override the default product-need taxonomy slug (default: pa_need).', 'ai-eshop-optimizer'),
                'example' => "add_filter('aieo_dmm_needs_taxonomy', fn() => 'my_needs');",
            ),
        );
    }
}
