<?php

namespace Digtective;

use Digtective\Controllers\ConnectionController;

final class Init{
    public static function get_services(){
        return [
            Pages\Admin::class,
            Base\SettingsLinks::class,
            ConnectionController::class,
            Base\Route::class,
            Integrations\GravityFormsIntegration::class,
        ];
    }

    public static function register_services(){
        self::registerAssets();

        foreach(self::get_services() as $class){
            $service = self::instantiate($class);

            if(method_exists($service, 'register')){
                $service->register();
            }
        }
    }

    public static function registerAssets(){
        add_action('wp_enqueue_scripts', function(){
            wp_enqueue_script('digtective-script', DIGTECTIVE_URL . 'Digtective/Assets/session.js', [], "1.1.4", false);
        });

        add_action('wp_enqueue_scripts', function(){
            wp_enqueue_script('digtective-paddle-script', DIGTECTIVE_URL . 'Digtective/Assets/paddle.js', [], '1.0.1', true);
        });

        add_action('wp_enqueue_scripts', function(){
            wp_enqueue_script('digtective-hubspot-script', DIGTECTIVE_URL . 'Digtective/Assets/hubspot.js', [], '1.0.1', true);
        });
    }

    private static function instantiate($class){
        return new $class();
    }
}
