<?php

namespace Devnet\PPH\Includes;

use Devnet\PPH\Admin\PPH_Admin;
use Devnet\PPH\Admin\Edit_Product;
use Devnet\PPH\Modules\Chart\Chart_Admin;
use Devnet\PPH\Modules\Chart\Edit_Product as ChartEditProduct;
use Devnet\PPH\Modules\Chart\Chart_Public;
use Devnet\PPH\Modules\LowestPrice\LP_Admin;
use Devnet\PPH\Modules\LowestPrice\LP_Public;
use Devnet\PPH\Modules\LowestPrice\LP_Custom;
if ( !defined( 'ABSPATH' ) ) {
    exit;
}
class PPH_Plugin {
    protected $plugin_name;

    protected $version;

    public function __construct() {
        if ( defined( 'PRODUCT_PRICE_HISTORY_VERSION' ) ) {
            $this->version = PRODUCT_PRICE_HISTORY_VERSION;
        } else {
            $this->version = '1.0.0';
        }
        $this->plugin_name = 'product-price-history';
        $this->load_dependencies();
    }

    private function load_dependencies() {
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/helper.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/settings-api.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/settings.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/admin.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/edit-product.php';
        /**
         * 
         * MODULES
         * 
         */
        // Chart
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'modules/chart/helper.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'modules/chart/admin.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'modules/chart/edit-product.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'modules/chart/public.php';
        // Lowest Price
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'modules/lowest-price/helper.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'modules/lowest-price/admin.php';
        require_once plugin_dir_path( dirname( __FILE__ ) ) . 'modules/lowest-price/public.php';
    }

    private function chart_module() {
        if ( defined( 'PPH_MODULE_CHART' ) && PPH_MODULE_CHART === false ) {
            return;
        }
        new Chart_Admin($this->get_plugin_name(), $this->get_version());
        new ChartEditProduct();
        new Chart_Public($this->get_plugin_name(), $this->get_version());
    }

    private function lowest_price_module() {
        if ( defined( 'PPH_MODULE_LOWEST_PRICE' ) && PPH_MODULE_LOWEST_PRICE === false ) {
            return;
        }
        new LP_Admin($this->get_plugin_name(), $this->get_version());
        new LP_Public($this->get_plugin_name(), $this->get_version());
    }

    public function run() {
        new PPH_Admin($this->get_plugin_name(), $this->get_version());
        new Edit_Product();
        $this->chart_module();
        $this->lowest_price_module();
    }

    public function get_plugin_name() {
        return $this->plugin_name;
    }

    public function get_version() {
        return $this->version;
    }

}
