<?php //phpcs:ignore
/**
 * Plugin Name: Kargo Entegratör
 * Plugin URI: https://kargoentegrator.com
 * Description: Kolay, hızlı, entegre edilebilir Woo kargo eklentisi 10’dan fazla firma ile entegre olun.
 * Version: 1.1.46
 * Author: GurmeHub
 * Author URI: https://gurmehub.com
 * Text Domain: kargo-entegrator
 * Requires at least: 6.4
 * Tested up to: 6.9
 * Requires PHP: 7.4
 * Requires Plugins: woocommerce
 * WC requires at least: 7.6
 * WC tested up to: 10.4.3
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 *
 * @package GurmeHub
 */

defined( 'ABSPATH' ) || exit;

/**
 * GurmeCargo eklenti anasınıfı.
 *
 * @package GurmeHub
 */
final class GurmeCargo {

	/**
	 * Eklenti öneki.
	 *
	 * @var string
	 */
	public $prefix = 'gcargo';

	/**
	 * Eklenti versiyonu.
	 *
	 * @var string
	 */
	public $version = '1.1.46';

	/**
	 * Veritabanı versiyonu.
	 *
	 * @var string
	 */
	public $db_version = '1.0.1';

	/**
	 * Sınıfın bir örneği.
	 *
	 * @var GurmeCargo|null
	 */
	protected static $instance;

	/**
	 * Sınıf örneklerini taşır.
	 *
	 * @var array
	 */
	public $container = [];

	/**
	 * GurmeCargo sınıfının bir örneğini türetir.
	 *
	 * @see GurmeCargo()
	 * @return GurmeCargo
	 */
	public static function get() {
		if ( is_null( self::$instance ) || ! ( self::$instance instanceof GurmeCargo ) ) {
			self::$instance = new GurmeCargo();
			self::$instance->setup();
		}
		return self::$instance;
	}

	/**
	 * Kurulum methodu.
	 *
	 * @return void
	 *
	 * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
	 */
	private function setup() {
		$this->define_constants();

		$this->includes();

		$this->instantiate();
	}

	/**
	 * Eklenti sabitleri tanımlama.
	 *
	 * @return void
	 */
	private function define_constants() {
		define( 'GCARGO_PREFIX', $this->prefix );
		define( 'GCARGO_VERSION', $this->version );
		define( 'GCARGO_DB_VERSION', $this->db_version );
		define( 'GCARGO_PRODUCTION', true );
		define( 'GCARGO_PLUGIN_BASEFILE', __FILE__ );
		define( 'GCARGO_AJAX_ACTION', 'gcargo_action' );
		define( 'GCARGO_PLUGIN_BASENAME', plugin_basename( __FILE__ ) );
		define( 'GCARGO_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) );
		define( 'GCARGO_PLUGIN_DIR_URL', plugin_dir_url( __FILE__ ) );
		define( 'GCARGO_ASSETS_DIR_URL', plugin_dir_url( __FILE__ ) . 'assets' );
	}

	/**
	 * Eklenti dosyaları yükleme.
	 *
	 * @SuppressWarnings(PHPMD.StaticAccess)
	 */
	public function includes() {
		$files = array(
			// Vendors
			'vendor/autoload.php',
			// Abstracts
			'includes/abstracts/abstract-gcargo-connection.php',
			'includes/abstracts/abstract-gcargo-resource.php',
			'includes/abstracts/abstract-gcargo-options.php',
			'includes/abstracts/abstract-gcargo-db-handler.php',
			'includes/abstracts/abstract-gcargo-mappers.php',

			// Resources
			'includes/resources/class-gcargo-warehouses-resource.php',
			'includes/resources/class-gcargo-cargo-integrations-resource.php',
			'includes/resources/class-gcargo-shipments-resource.php',
			'includes/resources/class-gcargo-returneds-resource.php',
			// Includes

			'includes/settings/class-gcargo-other-settings.php',
			'includes/settings/class-gcargo-auto-shipment-settings.php',
			'includes/settings/class-gcargo-wc-order-status-settings.php',
			'includes/settings/class-gcargo-saas-warehouses-settings.php',
			'includes/settings/class-gcargo-saas-cargo-integrations-settings.php',
			'includes/settings/class-gcargo-saas-shipment-settings.php',
			'includes/settings/class-gcargo-saas-returned-settings.php',
			'includes/settings/class-gcargo-gate-settings.php',
			'includes/settings/class-gcargo-package-settings.php',

			// Gate
			'includes/gate/class-gcargo-gate-rules.php',
			'includes/gate/class-gcargo-gate.php',

			'includes/class-gcargo-installer.php',
			'includes/class-gcargo-logger.php',
			'includes/class-gcargo-ajax-validation-exception.php',
			'includes/class-gcargo-api-key.php',
			'includes/class-gcargo-auto-shipment.php',
			'includes/class-gcargo-schedule.php',
			'includes/class-gcargo-data-handler.php',
			'includes/class-gcargo-meta-boxes.php',
			'includes/class-gcargo-http-client.php',
			'includes/class-gcargo-api-requests.php',
			'includes/class-gcargo-admin.php',
			'includes/class-gcargo-vue.php',
			'includes/class-gcargo-bulk-actions.php',
			'includes/class-gcargo-admin-notices.php',
			'includes/class-gcargo-shipment-map-wc-order.php',
			'includes/class-gcargo-returned-map-wc-order.php',
			'includes/class-gcargo-shipments-table.php',
			'includes/class-gcargo-returneds-table.php',
			'includes/class-gcargo-shipment.php',
			'includes/class-gcargo-returned.php',
			'includes/class-gcargo-shipments.php',
			'includes/class-gcargo-returneds.php',
			'includes/class-gcargo-wc-status-manager.php',

			// Functions
			'includes/gcargo-class-functions.php',
			'includes/gcargo-functions.php',
			// Hooks
			'hooks/class-gcargo-ajax.php',
			'hooks/class-gcargo-wordpress.php',
			'hooks/class-gcargo-actions.php',
			'hooks/class-gcargo-gph.php',
			'hooks/class-gcargo-woocommerce.php',
		);
		foreach ( $files as $file ) {
			require_once GCARGO_PLUGIN_DIR_PATH . $file;
		}
	}

	/**
	 * Sınıf türetme.
	 */
	public function instantiate() {
		$this->container = array(
			'GCARGO_WordPress' => new GCARGO_WordPress(),
			'GCARGO_Ajax'      => new GCARGO_Ajax(),
			'GCARGO_Actions'   => new GCARGO_Actions(),
			'GCARGO_Gph'       => new GCARGO_Gph(),
		);

		register_activation_hook( GCARGO_PLUGIN_BASEFILE, array( new GCARGO_Installer(), 'install' ) );
		$gurmehub_client = new \GurmeHub\Client( GCARGO_PLUGIN_BASEFILE );
		$gurmehub_client->insights();
	}

	/**
	 * Anasınıfı türetir ve eklentinin çalışmasını başlatır.
	 *
	 * @return GurmeCargo
	 *
	 * @SuppressWarnings(PHPMD.StaticAccess)
	 */
	public static function init() {
			return self::get();
	}
}

// Hadi başlayalım.
GurmeCargo::init();
