<?php
defined('ABSPATH') || exit;


require_once dirname(__DIR__) . '/domain/repositories/Review_Repository.php';
require_once dirname(__DIR__) . '/domain/repositories/Review_Media_Repository.php';
require_once dirname(__DIR__) . '/domain/repositories/Widget_Repository.php';
require_once dirname(__DIR__) . '/domain/repositories/Widget_Review_Repository.php';
require_once dirname(__DIR__) . '/domain/repositories/Form_Settings_Repository.php';
require_once dirname(__DIR__) . '/domain/repositories/Review_Request_Repository.php';
require_once dirname(__DIR__) . '/services/DSProofwp_Recaptcha_Service.php';
require_once dirname(__DIR__) . '/services/DSProofwp_AliExpress_Scraper.php';

require_once __DIR__ . '/controller/Reviews_Controller.php';
require_once __DIR__ . '/controller/Import_Controller.php';
require_once __DIR__ . '/controller/Widgets_Controller.php';
require_once __DIR__ . '/controller/Form_Settings_Controller.php';
require_once __DIR__ . '/controller/Product_Controller.php';
require_once __DIR__ . '/controller/Review_Request_Controller.php';
require_once __DIR__ . '/controller/Media_Controller.php';

class DSProofwp_Router
{
    public static function init(): void
    {
        add_action('rest_api_init', [self::class, 'register_routes']);
    }

    public static function register_routes(): void
    {
        global $wpdb;

        // Shared service — one instance used across controllers that need it
        $recaptcha_service       = new DSProofwp_Recaptcha_Service();
        $form_settings_repo      = new DSProofwp_Form_Settings_Repository($wpdb, $recaptcha_service);

        $controllers = [
            new DSProofwp_Reviews_Controller(
                new DSProofwp_Review_Repository($wpdb),
                new DSProofwp_Review_Media_Repository($wpdb),
                new DSProofwp_Widget_Review_Repository($wpdb),
                $recaptcha_service,
                $form_settings_repo
            ),
            new DSProofwp_Import_Controller(
                new DSProofwp_Review_Repository($wpdb),
                new DSProofwp_Review_Media_Repository($wpdb)
            ),
            new DSProofwp_Widgets_Controller(
                new DSProofwp_Widget_Repository($wpdb),
                new DSProofwp_Widget_Review_Repository($wpdb),
                new DSProofwp_Review_Repository($wpdb),
                new DSProofwp_Review_Media_Repository($wpdb)
            ),
            new DSProofwp_Form_Settings_Controller(
                $form_settings_repo
            ),
            new DSProofwp_Review_Request_Controller(
                new DSProofwp_Review_Request_Repository($wpdb)
            ),
            new DSProofwp_Product_Controller(),
            new DSProofwp_Media_Controller(
                $form_settings_repo
            ),
        ];

        foreach ($controllers as $controller) {
            $controller->register_routes();
        }
    }
}
