<?php

namespace PWH_DCFH\App\Controllers;

use PWH_DCFH\App\Admin\Cron\PWH_DCFH_Entries_Auto_Delete;
use PWH_DCFH\App\Base\PWH_DCFH_Plugin_Meta_Links;
use PWH_DCFH\App\Base\PWH_DCFH_Public_Enqueue;
use PWH_DCFH\App\Base\PWH_DCFH_Admin_Enqueue;
use PWH_DCFH\App\Admin\CPT\PWH_DCFH_Contact_Form_Entries;
use PWH_DCFH\App\Admin\CPT\PWH_DCFH_Contact_Form_Metaboxes;
use PWH_DCFH\App\Admin\Pages\PWH_DCFH_Create_Post;
use PWH_DCFH\App\Admin\Pages\PWH_DCFH_Create_Email_Template;
use PWH_DCFH\App\Admin\Pages\PWH_DCFH_Email_Templates;
use PWH_DCFH\App\Admin\Pages\PWH_DCFH_Send_Email;
use PWH_DCFH\App\Admin\Pages\PWH_DCFH_Export_CSV;
use PWH_DCFH\App\Admin\Controllers\PWH_DCFH_Dashboard_Stats;
use PWH_DCFH\App\Admin\Controllers\PWH_DCFH_SMTP;
use PWH_DCFH\App\Admin\Cron\PWH_DCFH_Entries_Auto_Backup;
use PWH_DCFH\App\Admin\Settings\PWH_DCFH_Epanel_Settings;
use PWH_DCFH\App\Admin\Logger\PWH_DCFH_Logger;
use PWH_DCFH\App\Admin\Cron\PWH_DCFH_Delete_Tmp_Files;
use PWH_DCFH\App\Admin\Pages\PWH_DCFH_Contact_Forms;
use PWH_DCFH\App\Frontend\DiviContactForm\PWH_DCFH_Filter_Contact_Form;
use PWH_DCFH\App\Frontend\DiviContactForm\PWH_DCFH_Filter_Contact_Form_Fields;
use PWH_DCFH\App\Frontend\Request\PWH_DCFH_Process_Form_Request;

if (!defined('ABSPATH')) exit;
if (!class_exists('PWH_DCFH_Autoload')) {
    class PWH_DCFH_Autoload
    {
        /**
         * Get Class Instance
         *
         * @param $class
         *
         * @return mixed
         */
        private static function instantiate($class)
        {
            return new $class();
        }

        /**
         * Classes
         * @return string[]
         */
        private static function services()
        {
            $services = [
                PWH_DCFH_Public_Enqueue::class,
                PWH_DCFH_Contact_Form_Entries::class,
                PWH_DCFH_Filter_Contact_Form::class,
                PWH_DCFH_Filter_Contact_Form_Fields::class,
                PWH_DCFH_Process_Form_Request::class,
                PWH_DCFH_Entries_Auto_Backup::class,
                PWH_DCFH_Entries_Auto_Delete::class,
                PWH_DCFH_Delete_Tmp_Files::class,
                PWH_DCFH_SMTP::class,
            ];
            if (is_admin()) {
                $services[] = PWH_DCFH_Plugin_Meta_Links::class;
                $services[] = PWH_DCFH_Admin_Enqueue::class;
                $services[] = PWH_DCFH_Contact_Form_Metaboxes::class;
                $services[] = PWH_DCFH_Create_Post::class;
                $services[] = PWH_DCFH_Create_Email_Template::class;
                $services[] = PWH_DCFH_Email_Templates::class;
                $services[] = PWH_DCFH_Send_Email::class;
                $services[] = PWH_DCFH_Export_CSV::class;
                $services[] = PWH_DCFH_Contact_Forms::class;
                $services[] = PWH_DCFH_Dashboard_Stats::class;
                $services[] = PWH_DCFH_Epanel_Settings::class;
                $services[] = PWH_DCFH_Logger::class;
            }

            return $services;
        }

        /**
         * Autoload Classes
         * @return void
         */
        public static function register_services()
        {
            foreach (self::services() as $class) {
                $service = self::instantiate($class);
                if (method_exists($service, 'init')) {
                    $service->init();
                }
            }
        }

    }
}